Implement The Following Sorting Algorithms
Implement The Following Sorting Algorithms
Main()
2- bubble
3- Insertion
4- Merge
5 – Quick
6 – Heap
45, 37, 28, 78, 50, 14, 87, 43
We are finding the position of smallest element in the unsorted array, we exchanging with the
element in position 0.
Small_index = 0;
For (j = 1 to n-1)
If(a[j]<a[small_index])
Small_index = j;
Small_index = 1;
For (j = 2 to n-1)
If(a[j]<a[small_index])
Small_index = j;
Pass2:
Small_index = 2;
For (j = 3 to n-1)
If(a[j]<a[small_index])
Small_index = j;
Pass6:
Selection_Sort(A, n)
For(i= 0 to n-2)
{ Small_index = i;
{If(a[j]<a[small_index])
Small_index = j;
For(k=0 to n-1)
Print a[k];
}
45, 37, 28, 78, 50, 14, 87, 43
Pass 0:
50, 78
14, 78
78, 87
We are finding the position of smallest element in the unsorted array, we exchanging with the
element in position 0.
0–1
1–2
2–3
n-2 – n-1
For (j = 0 to n-i-2)
If(a[j]>a[j+1])
0–1
1–2
2–3
n-3 – n-2
Small_index = 1;
For (j = 2 to n-1)
If(a[j]<a[small_index])
Small_index = j;
Pass2:
Small_index = 2;
For (j = 3 to n-1)
If(a[j]<a[small_index])
Small_index = j;
Pass6:
Bubble_sort(A, n)
For (j = 0 to n-i-2)
If(a[j]>a[j+1])