SORTING USING INSERTION SORT

788

SORTING USING INSERTION SORT

BCA Third Semester

Data Structure

 

 

#include <stdio.h>
#include <conio.h>

int main()
{
int n, array[1000], c, d, t;
clrscr();
printf(“Enter number of elements : “);
scanf(“%d”, &n);

printf(“Enter %d integers\n”, n);

for (c = 0; c < n; c++) {
scanf(“%d”, &array[c]);
}

for (c = 1 ; c <= n – 1; c++) {
d = c;

while ( d > 0 && array[d] < array[d-1]) {
t = array[d];
array[d] = array[d-1];
array[d-1] = t;

d–;
}
}

printf(“Sorted list in ascending order:\n”);

for (c = 0; c <= n – 1; c++) {
printf(“%d\n”, array[c]);
}

getch();
return 0;
}

OUTPUT
Enter number of elements : 5
Enter 5 integers
40
10
30
60
20

Sorted list in ascending order:
10
20
30
40
60

 

 

if you need a Downloadable link once message us on-page you can get at a time.

m.me/bcanotesnepal

This post is posted for not further third-party purposes.

Copyright By:-  Bcanotesneapl

Not allowed to upload these notes to other sites.

Like our Facebook Page https://www.facebook.com/bcanotesnepal/

if you want to download this PDF comment on us we will provide you a downloadable link.

if you like please share this post with your friend who studies in BCA

if you have any query please comment below,

if you like our sites. you can visit again for the latest updates notes of different BCA subjects of Presentation and different topics with assignment questions and solutions.

Don’t forget to like our page and post also share with your friend and having your group.

if you have any questions you can drop or share them with me using the comment box I will try to answer your question.

Like our Facebook Page https://www.facebook.com/bcanotesnepal/

LEAVE A REPLY

Please enter your comment!
Please enter your name here