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[*]}
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.