A simple shell sort program that I wrote using C programming language.
I am currently accepting programming work, IT projects, school and application development, programming projects, thesis and capstone projects, IT consulting work, computer tutorials, and web development work kindly contact me at the following email address for further details. If you want to advertise on my website, kindly contact me also at my email address also. Thank you.
My email address is jakerpomperada@gmail.com and jakerpomperada@yahoo.com
My mobile number here in Bacolod City, Negros Occidental Philippines is 09173084360.
Program Listing
/* shell_sort.c
Author : Mr. Jake Rodriguez Pomperada,MAED-IT, MIT
Tool : Dev C++ 5.11
Date : August 15, 2021 Sunday 4:29 PM
Websites : www.jakerpomperada.com and www.jakerpomperada.blogspot.com
Email :jakerpomperada@gmail.com
Location : Bacolod City, Negros Occidental, Philippines
*/
#include <stdio.h>
#include <stdlib.h>
void shellsort(int arr[], int num);
int main()
{
int items[1000], num=0,min=0,loc=0;
int c=0, b=0,change=0,j=0,temp=0;
system("cls");
printf("\n\n");
printf("\tShell Sort Program in C");
printf("\n\n");
printf("\tHow many items? : ");
scanf("%d", &num);
printf("\n\n");
for (c= 0; c < num; c++) {
printf("\tEnter item no. %d: ", c+1);
scanf("%d", &items[c]);
}
printf("\n\n");
printf("\tOriginal Arrangement of Numbers");
printf("\n\n");
for ( c = 0 ; c < num ; c++ ) {
printf("\t%d ",items[c]);
}
shellsort(items, num);
printf("\n\n");
printf("\tAsceding Order of Numbers");
printf("\n\n");
for ( c = 0 ; c < num ; c++ ) {
printf("\t%d ", items[c]);
}
printf("\n\n");
printf("\tEnd of Program");
printf("\n\n");
system("pause");
}
void shellsort(int arr[], int num)
{
int i, j, k, tmp;
for (i = num / 2; i > 0; i = i / 2)
{
for (j = i; j < num; j++)
{
for(k = j - i; k >= 0; k = k - i)
{
if (arr[k+i] >= arr[k])
break;
else
{
tmp = arr[k];
arr[k] = arr[k+i];
arr[k+i] = tmp;
}
}
}
}
}