Logo 
Search:

Unix / Linux / Ubuntu Articles

Submit Article
Home » Articles » Unix / Linux / Ubuntu » Homework HelpRSS Feeds

Write a shell script to sort the given numbers in descending order using Bubble sort

Posted By: Isla Hughes     Category: Unix / Linux / Ubuntu     Views: 25968

Write a shell script to sort the given numbers in
descending order using Bubble sort

Code for Write a shell script to sort the given numbers in descending order using Bubble sort in Unix / Linux / Ubuntu

echo
i=1
k=1
echo "Enter no. of integers to be sorted"
read n
echo
echo "Enter the numbers"while [ $i -le $n ]
do
read num
x[$k]=`expr $num`
i=`expr $i + 1`
k=`expr $k + 1`
done
x[$k]=0
k=1
echo
echo "The number you have entered are"while [ ${x[$k]} -ne 0 ]
do
echo "${x[$k]}"
echo
k=`expr $k + 1`
done
k=1
while [ $k -le $n ]
do
j=1
while [ $j -lt $n ]
do
y=`expr $j + 1`
if [ ${x[$j]} -gt ${x[$y]} ]
then
temp=`expr ${x[$j]}`
x[$j]=`expr ${x[$y]}`
x[$y]=`expr $temp`
fi
j=`expr $j + 1`
done
k=`expr $k + 1`
done
k=1
echo
echo "Number in sorted order..."
echo
while [ ${x[$k]} -ne 0 ]
do 
echo "${x[$k]}"
echo 
k=`expr $k + 1`
done
  
Share: 



Isla Hughes
Isla Hughes author of Write a shell script to sort the given numbers in descending order using Bubble sort is from London, United Kingdom.
 
View All Articles

 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!