Custom Search

Monday, 3 September 2012

Write a Linux shell script for Selection Sort, Write a program in pl/sql program for sorting


Write a Linux shell script for Selection Sort, Write a program in pl/sql program for sorting


Program
echo "please enter the number"
read n
echo "please enter number an array"
for((i=0;i<n;i++))
do
read arr[$i]
done

#process for selection sort

for((i=0;i<n-1;i++))
do
small=${arr[$i]}
index=$i
for((j=i+1;j<n;j++))
do
if((arr[j]<small))
then
small=${arr[$j]}
index=$j
fi
done
temp=${arr[$i]}
arr[$i]=${arr[$index]}
arr[$index]=$temp
done

#printing sorted array

echo "printed sorted array is:"
for((i=0;i<n;i++))
do
echo ${arr[$i]}
done

Click here to check the output

No comments:

Post a Comment

Laptops