Advertisement
varungurnaney

OST: Insertion Sort

Dec 7th, 2014
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.22 KB | None | 0 0
  1. #!/bin/bash
  2. read -a ar
  3. l=${#ar[*]}
  4. temp=0
  5. for(( i=0; i<$l; i++ ))
  6. do
  7. for(( j=i; j>0; j-- ))
  8. do
  9. if [ ${ar[j-1]} -gt ${ar[j]} ]
  10. then
  11. temp=${ar[j-1]}
  12. ar[j-1]=${ar[j]}
  13. ar[j]=$temp
  14. fi
  15. done
  16. done
  17.  
  18. echo ${ar[*]}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement