Insertion Sort in C

Insertion Sort in C

Here you will learn algorithm of insertion sort and get the program code 0f Insertion Sort in C without function using c language.

 

What is Insertion Sort?

Insertion sort is a sorting algorithm that places an unsorted element into its proper position within a sorted array. It loops through the array, beginning with the second element and comparing each element to the one before it. If the element being compared is smaller than the one before it, they are swapped. This process is repeated again until an array is sorted in an order.

 

Algorithm of Insertion Sort in C

Insertion sort(ar[],n)
for j->2 to n
do key <-ar[j]
i<-j-1
while i>=0 and ar[i]>key
do ar[i+1]<-ar[i]
i<-i+1
ar[i+1]<-key
end

 

Insertion Sort Flowchart (DFD)

 Insertion Sort in C Flowchart

 

Example of Insertion Sort in C without function

Output

Insertion Sort in C program output

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top