Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 9

Ex.

No:2(a) BUBBLE SORT


Date: 11.08.2020

Aim:
To write a C program to perform bubble sort in array.

Algorithm:
1. Initialize the array value.
2. Enter the array elements.
3. If i=0 and j=0, compare the adjacent array elements.
4. If a[i]>a[j], then swap the array elements.
5. Compare and swap the elements until the array elements is sorted in ascending order.

Program:

R.KAVIBHARATH
1901102
CSE-B
Output:

Output:
Thus, the C program to perform bubble sort was executed successfully.

R.KAVIBHARATH
1901102
CSE-B
Ex.No:2(b) INSERTION SORT
Date: 11.08.2020

Aim:
To write a C program to perform insertion sort on array.

Algorithm:
1. Enter the array elements.
2. Consider, the array element a[1].
3. Compare a[1] with a[0].
4. If a[0]>a[1], then swap the array element.
5. Compare the other array elements in the array and sort the elements.

Program:

R.KAVIBHARATH
1901102
CSE-B
Output:

Result:
Thus, the C program to perform insertion sort was executed successfully.

R.KAVIBHARATH
1901102
CSE-B
Ex.No:2(c) MERGE SORT
Date: 11.08.2020

Aim:
To write a C program to perform merge sort in array.

Algorithm:
1. Initialize the array values.
2. Enter the array elements.
3. Divide the array elements into two temporary arrays.
4. Divide the arrays into temporary arrays.
5. Arrange the temporary arrays in ascending order.
6. Merge the sorted temporary arrays into a single array.

Program:

R.KAVIBHARATH
1901102
CSE-B
R.KAVIBHARATH
1901102
CSE-B
Output:

R.KAVIBHARATH
1901102
CSE-B
Result:
Thus, the C program to perform merge sort was executed successfully.

R.KAVIBHARATH
1901102
CSE-B
R.KAVIBHARATH
1901102
CSE-B

You might also like