please help really need


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting please help really need
# 8  
Old 09-02-2010
yes it is homework...
Code:
#!/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 than the next then swap the
             # values.
          if [ ${num[i]} -gt ${num[j]} ]
          then
                temp=${num[i]}
                num[i]=${num[j]}
                num[j]=$temp
          fi
      i=$j
  done
  x=$[$x-1]
  done
  
  # Display the sorted array
  echo "Sorted Output --"
  echo ${num[*]}

may take bubble sort and remake it that she would leave the zeros in the right place
# 9  
Old 09-02-2010
Homework should be posted here, adhering to these rules, thank you very much, thread closed.
Login or Register to Ask a Question

Previous Thread | Next Thread
Login or Register to Ask a Question