Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- void swap(int *a, int *b){
- if(*a != *b){
- int t = *a; *a = *b; *b = t;
- }
- }
- void shellSort(int a[], int n){
- int i, j, k;
- for(i = n/2; i > 0; i = i/2)
- for(j = i; j < n; j++)
- for(k = j - i; k >= 0; k = k - i)
- if(a[k+i] < a[k]) swap(&a[k+i], &a[k]);
- else break;
- }
- int main(){
- int *a, i, n;
- printf("Enter the number of elements : ");
- scanf("%d", &n);
- a = (int *) malloc(sizeof(int) *n);
- for(i = 0; i < n; i++) scanf("%d", &a[i]);
- shellSort(a, n);
- printf("The sorted list is:-\n");
- for(i=0; i<n; i++) printf("%d\t", a[i]);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement