please help

 
Thread Tools Search this Thread
Homework and Emergencies Homework & Coursework Questions please help
# 1  
Old 09-02-2010
please help

Must be organized to function as one-dimensional array, leaving in place the zero elements.I think lots of people here who can help, I think possibly take any sort, and transform, I took a bubble but it gives an error ..
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[*]}

# 2  
Old 09-02-2010
Lets try this again. When posting here, these rules are in effect:
https://www.unix.com/homework-coursew...ons-forum.html
Especially important is this part
Quote:
Please Note: Posting homework or coursework without complete school/city/country/professor/course information, you will be banned if you post here! Also, members who answer homework or coursework questions (assist students) that post without complete school/city/country/professor/course information will be given infractions. This complete information is mandatory.
Thread closed.
Login or Register to Ask a Question

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