Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions Sorting/Insertion Sort/insertionSort.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@

/*INSERTION SORT MECHANISM */

#include<stdio.h>
int main(){

int i, j, c, t, number[25];

printf("Enter the total number of elements:");
scanf("%d",&c);

printf("Enter %d elements: ", c);
// Loop to fill the array with the input numbers

for(i=0;i<c;i++)
scanf("%d",&number[i]);

// Here, the working of the insertion sort mechanism starts
for(i=1;i<c;i++){
t=number[i];
j=i-1;
while((t<number[j])&&(j>=0)){
number[j+1]=number[j];
j=j-1;
}
number[j+1]=t;
}

printf("Order of Sorted elements: ");
for(i=0;i<c;i++)
printf(" %d",number[i]);

return 0;
}