Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- printArray(){
- echo ${a[*]}
- }
- exchange(){
- temp=${a[$1]}
- a[$1]=${a[$2]}
- a[$2]=$temp
- }
- bubbleSort(){
- for (( i=0; i<$n; i++ ))
- do
- for(( j=$i; j<$n; j++ ))
- do
- if [ ${a[i]} -gt ${a[j]} ]
- then exchange $i $j
- fi
- done
- done
- }
- echo "Enter the numbers to be sorted:-"
- read -a a
- n=${#a[@]}
- bubbleSort
- printArray
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement