0% found this document useful (0 votes)
4 views2 pages

Shell Sort Algorithm in C Code

The document describes an experiment to implement Shell Sort in C programming. It includes the code to perform Shell Sort on an integer array using intervals and swapping elements. It inputs an unsorted array, runs Shell Sort on it, and prints out the sorted array as output.

Uploaded by

Prakhar Pandey
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views2 pages

Shell Sort Algorithm in C Code

The document describes an experiment to implement Shell Sort in C programming. It includes the code to perform Shell Sort on an integer array using intervals and swapping elements. It inputs an unsorted array, runs Shell Sort on it, and prints out the sorted array as output.

Uploaded by

Prakhar Pandey
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

EXPERIMENT-6

AIM- Shell Sort in C programming

#include <stdio.h

void shellSort(int array[], int n)

{ for (int interval = n / 2; interval > 0; interval /= 2) {

for (int i = interval; i < n; i += 1) {

int temp = array[i];

int j;

for (j = i; j >= interval && array[j - interval] > temp; j -= interval) {

array[j] = array[j - interval];

array[j] = temp;

void printArray(int array[], int size) {


for (int i = 0; i < size; ++i) {

printf("%d ", array[i]);


}
printf("\n");

int main() {

int data[] = {9, 8, 3, 7, 5, 6, 4, 1};

int size = sizeof(data) / sizeof(data[0]);

shellSort(data, size);

printf("Sorted array: \n");

printArray(data, size);

OUTPUT- 1 3 4 5 6 7 8 9

Prakhar Pandey
2100271540039
CSE-DS

You might also like