Notice: Undefined index: url2 in
/home/u681245571/domains/studyglance.in/public_html/labprograms/dsdisplay.php on line
83
Notice: Undefined index: url3 in
/home/u681245571/domains/studyglance.in/public_html/labprograms/dsdisplay.php on line
84
Notice: Undefined index: url4 in
/home/u681245571/domains/studyglance.in/public_html/labprograms/dsdisplay.php on line
85
Notice: Undefined index: title in
/home/u681245571/domains/studyglance.in/public_html/labprograms/dsdisplay.php on line
86
Notice: Undefined index: opurl2 in
/home/u681245571/domains/studyglance.in/public_html/labprograms/dsdisplay.php on line
88
Notice: Undefined index: opurl3 in
/home/u681245571/domains/studyglance.in/public_html/labprograms/dsdisplay.php on line
89
Notice: Undefined index: opurl4 in
/home/u681245571/domains/studyglance.in/public_html/labprograms/dsdisplay.php on line
90
Aim:
Source Code:
insertionsort.c
#include<stdio.h>
int main()
{
int i,n,a[20];
printf("enter n value");
scanf("%d",&n);
printf("enter %d elements",n);
for(i=1;i<=n;i++)
{
scanf("%d",&a[i]);
}
insertion(a,n);
printf("after sorting\n");
for(i=1;i<=n;i++)
{
printf("%d\t",a[i]);
}
getch();
return 1;
}
int insertion(int a[],int n)
{
int i,j,b[120];
b[1]=a[1];
for(i=2;i<=n;i++)
{
for(j=i-1;j>=1&&b[j]>a[i];j--)
{
b[j+1]=b[j];
}
b[j+1]=a[i];
}
for(i=1;i<=n;i++)
a[i]=b[i];
}
Output:
Related Content :
Data Structures Lab Programs
1) Write a C program that uses functions to perform the following on Singly Linked List:
i) Creation
ii) Insertion
iii) Deletion
iv) Traversal
View Solution
2) Write a program that uses functions to perform the following operations on Doubly Linked List.:
i) Creation
ii) Insertion
iii) Deletion
iv) Traversal
View Solution
3) Write a program that uses functions to perform the following operations on Circular Linked List.:
i) Creation
ii) Insertion
iii) Deletion
iv) Traversal
View Solution
4) Write a program that implement Stack (its operations) using Arrays
View Solution
5) Write a program that implement Stack (its operations) using Pointers
View Solution
6) Write a program that implement Queue (its operations) using Arrays
View Solution
7) Write a program that implement Queue (its operations) using Pointers
View Solution
8) Write a program that implements Bubble Sort Method to sort a given list of integers in ascending order.
View Solution
9) Write a program that implements Selection Sort Method to sort a given list of integers in ascending order.
View Solution
10) Write a program that implements Insertion Sort Method to sort a given list of integers in ascending order.
View Solution
11) Write a program that use both recursive and non recursive functions to perform Linear search operations for a Key value in a given list of integers.
View Solution
12) Write a program that use both recursive and non recursive functions to perform Binary search operations for a Key value in a given list of integers.
View Solution
13) Write a program to implement the tree traversal methods.
View Solution
14) Write a program to implement Depth First Search (DFS) graph traversal methods.
View Solution
15) Write a program to implement Breadth First Search (BFS) graph traversal methods.
View Solution