Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint

Bubble_sort.sh

# Sorting the array in Bash 
# using Bubble sort 

# Static input of Array 
arr = (10 8 20 100 12) 

echo "Array in original order"
echo ${arr[*]} 

# Performing Bubble sort 
for ((i = 0; i<5; i++)) 
do
	
	for((j = i; j<5-i-1; j++)) 
	do
	
		if ((${arr[j]} > ${arr[$((j+1))]})) 
		then
			# swap 
			temp = ${arr[$j]} 
			arr[$j] = ${arr[$((j+1))]} 
			arr[$((j+1))] = $temp 
		fi
	done
done

echo "Array in sorted order :"
echo ${arr[*]} 

Advertisements
Loading...

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.