Exno: 3 Insertion Sort Aim
Exno: 3 Insertion Sort Aim
Aim:
Algorithm:
1. Start
2. Read the elements from user.
3. If it is the first element, it is already sorted. return 1;
4. Pick next element
5. Compare with all elements in the sorted sub-list
6. Shift all the elements in the sorted sub-list that is greater than the value
to be sorted
7. Insert the value
8. Repeat until list is sorted
9. Stop
Coding:
#include <stdio.h>
int main()
{
int n, array[1000], c, d, t;
d--;
}
}
return 0;
}
Sample Output:
How many elements?
4
Enter 4 elements:
4
5
8
9
Sorted list in ascending order:
4589
EX.NO:4 BUBBLE SORT
Aim:
To implement a Bubble sort algorithm using C.
Algorithm:
1. Start
2. Read list of elements
3. for all elements of list check if list[i] > list[i+1]
4. if true swap(list[i], list[i+1])
5. return list
6. Stop
Coding:
#include <stdio.h>
int main()
{
int array[100], n, c, d, swap;
return 0;
}
Sample Output:
How many elements?
4
Enter 4 elements:
4
5
8
9
Sorted list in ascending order:
4589