31
									
								
								14.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										31
									
								
								14.c
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,31 @@
 | 
				
			|||||||
 | 
					#include <math.h>
 | 
				
			||||||
 | 
					#include <stdio.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void shell_sort(int arr[], int n) {
 | 
				
			||||||
 | 
					  for (int g = n / 2; g > 0; g /= 2) {
 | 
				
			||||||
 | 
					    for (int i = g; i < n; i++) {
 | 
				
			||||||
 | 
					      int x = arr[i], j;
 | 
				
			||||||
 | 
					      for (j = i; j >= g && arr[j - g] > x; j -= g)
 | 
				
			||||||
 | 
					        arr[j] = arr[j - g];
 | 
				
			||||||
 | 
					      arr[j] = x;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void display(int arr[], int n) {
 | 
				
			||||||
 | 
					  for (int i = 0; i < n; i++)
 | 
				
			||||||
 | 
					    printf("%d ", arr[i]);
 | 
				
			||||||
 | 
					  printf("\n");
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					int main() {
 | 
				
			||||||
 | 
					  const int SIZE = 5;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  int arr[] = {93, 110, 12398, -5, 2};
 | 
				
			||||||
 | 
					  printf("Insertion Sort on: ");
 | 
				
			||||||
 | 
					  display(arr, SIZE);
 | 
				
			||||||
 | 
					  shell_sort(arr, SIZE);
 | 
				
			||||||
 | 
					  display(arr, SIZE);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  return 0;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
		Reference in New Issue
	
	Block a user