It will perform bubble sort using array function with seq command. Seq refers to sequence seq0$[no-1].
Source code bash shell Programming Algorithm
echo “Enter the size of array”
read no
i=0
echo “Enter the numbers”
for i in `seq 0 $[$no – 1]`
do
read arr[i]
done
for i in `seq 0 $[$no – 1]`
do
j=0
while [ $j –lt $[$no - $i – 1]]
do
if [ $[arr[j]] –gt $[arr[$j + 1]]]
then
tmp=$[arr[$j]]
arr[$j]=$[arr[$j + 1]]
arr[$j + 1]=$tmp
fi
j=`expr $j + 1`
done
done
echo “The ordered array is……”
for i in `seq 0 $[$no – 1]`
do
echo “$[arr[$i]]”
done
BUBBLE SORT OUTPUT CS1252 Operating Systems lap
[redhat35@localhost Rhel5]$ sh bubble.sh
Enter the size of array
5
Enter the numbers
100
50
87
14
25
The ordered array is……
14
25
50
87
100
Friday, May 14, 2010
Bubble Sort Bash Shell Programming With Array And Seq Command Linux Unix
Subscribe to:
Post Comments (Atom)
Labels
3D-2D Translation
Algorithms
Batch Programming
C language
C world
C++
DBMS
Ebook
Games
JAVA
Java Programs
JNTU MATERIALS
JNTU PREVIOUS QUESTION PAPERS
JNTU SYLLABUS BOOKS
LAB MANUALS
Linux
Mobile softwares
Networking
Online Programs
PC TIPS
Software Diagrams
Software Engineering
Softwares
System Software
Visual Basic
0 comments:
Post a Comment