Write a Linux shell script for Insertion Sort, Write a program in pl/sql program for insertion sorting
Program
echo "please enter the number"
read n
echo "please enter number in an array"
for((i=0;i<n;i++))
do
read arr[$i]
done
#logic for insertion sort
for((i=1;i<n;i++))
do
j=$i-1
temp=${arr[$i]}
while((j>=0 && arr[j]>temp))
do
arr[$j+1]=${arr[$j]}
j=$j-1
done
arr[j+1]=$temp
done
#printing sorted array
echo "printing sorted array"
for((i=0;i<n;i++))
do
echo ${arr[$i]}
done
Click here to check the output
No comments:
Post a Comment