Uploaded by [60] Sahil Ahmad

Sorting Algorithms in C

advertisement
DATA STRUCTURES USING C
ASSIGNMENT 1
Sahil Ahmad (null)
sahillangoo@protonmail.com
3rd Semester
Assign Date: 27-Feb-21
LECTURER
Bisma
(Assistant Professor)
DEPARTMENT OF COMPUTER SCIENCE &
ENGINEERING
UNIVERSITY OF KASHMIR, SRINAGAR
(NORTH CAMPUS)
TABLE OF CONTENT
Programs
a. Bubble Sort
b. Insertion Sort
c. Selection Sort
2
Bubble Sort
Algorithm:
start
bubbleSort(array)
for i <- 1 to indexOfLastUnsortedElement-1
if leftElement > rightElement
swap leftElement and rightElement
end bubbleSort
Program:
3
Result:
4
Insertion Sort
Algorithm:
Start
insertionSort(array)
mark first element as sorted
for each unsorted element X
'extract' the element X
for j <- lastSortedIndex down to 0
if current element j > X
move sorted element to the right by 1
break loop and insert X here
end insertionSort
Program:
5
Result:
6
Selection Sort
Algorithm:
Start
selectionSort(array, size)
repeat (size - 1) times
set the first unsorted element as the minimum
for each of the unsorted elements
if element < currentMinimum
set element as new minimum
swap minimum with first unsorted position
end selectionSort
Program:
7
Result:
8
Download