# Tutorial 6 - Tutorial 6 In this tutorial we are going to...

This preview shows pages 1–3. Sign up to view the full content.

Tutorial 6 In this tutorial, we are going to familiarize ourselves with some sorting algorithms using shell programming. We will deal with bubble sort and insertion sort. We will also create some scripts ourselves as exercise. Use Vi, Emacs or Pico for editing the scripts. Login to one of the following Unix servers: cs1.utdallas.edu cs2.utdallas.edu Use PuTTY or Xmanager for logging on as you learnt in Tutorial 1 . First example script: Bubble Sort In our first example, we will write a script which will sort and print an array of integers or characters whose size is dynamically determined. Open your favorite Unix editor and type in the following script: The bubble sort algorithm can be accessed through Bubble Sort . Here is the script:

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
#!/bin/bash # Bubble Sort echo "Input unsorted numbers --" read -a num numlen=\${#num[*]} # Sort the array x=\$numlen temp=0 # Standard algorithm for bubble sort while [ \$x -gt 0 ]; do i=0 while [ \$i -lt \$[\$numlen-1] ]; do j=\$[\$i+1] # If the previous element in the array is greater
This is the end of the preview. Sign up to access the rest of the document.

## This note was uploaded on 12/12/2009 for the course CS 3375 taught by Professor Kendracooper during the Fall '08 term at University of Texas at Dallas, Richardson.

### Page1 / 4

Tutorial 6 - Tutorial 6 In this tutorial we are going to...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online