1: #include<stdio.h>
2: #include<conio.h>
3: void main()
4: {
5: int a[20];
6: int i,j,k,temp,n;
7: clrscr();
8: printf("Enter the number of elements to be sorted:\n");
9: scanf("%d",&n);
10: printf("Enter the elements:\n");
11: for(i=0;i<n;i++)
12: {
13: scanf("%d",&a[i]);
14: }
15: for(i=n/2;i>0;i=i/2)
16: {
17: for(j=i;j<n;j++)
18: {
19: for(k=j-i;k>=0;k=k-i)
20: {
21: if(a[k+i]>=a[k])
22: break;
23: else
24: {
25: temp=a[k];
26: a[k]=a[k+i];
27: a[k+i]=temp;
28: }
29: }
30: }
31: }
32: printf("\nArray elements after shell sorting are:\n");
33: for(i=0;i<n;i++)
34: {
35: printf("%d\t",a[i]);
36: }
37: getch();
38: }
getsprogramming Tutorials , C Programming, CPP Programming and JAVA Programming , Python Programming , Javascript Programming Welcome to getsprogramming Blog Here You Find Different Programs in Easier way to Explain and gain Knowledge and Try Your Self..Thanks
Showing posts with label Shell Sort. Show all posts
Showing posts with label Shell Sort. Show all posts
Tuesday, 29 September 2015
Write a C Program To Perform Shell Sort
Subscribe to:
Posts (Atom)