I wrote this program that will accept ten numbers and then the program will sort the given number and display the sorted values using shell sort algorithm using C++ programming language.
My email address is the following jakerpomperada@gmail.com, jakerpomperada@aol.com, and jakerpomperada@yahoo.com.
My mobile number here in the Philippines is 09173084360.
My telephone number at home here in Bacolod City, Negros Occidental Philippines is +63 (034) 4335675.
Here in Bacolod City, Negros Occidental I also accepting computer repair, networking and Arduino Project development at a very affordable price.
My Facebook address is https://www.facebook.com/profile.php?...
My personal website is http://www.jakerpomperada.com
My programming website is http://www.jakerpomperada.blogspot.com
I am also a book author you can purchase my books on computer programming and information technology in the following links below.
https://www.mindshaperspublishing.com/
https://www.unlimitedbooksph.com/
Thank you very much for your help and support.
Sample Program Output
Program Listing
shell.cpp
// shell_sort.cpp
// Jake R. Pomperada, MAED-IT
// December 2, 2019
#include <iostream>
using namespace std;
void shellSort(int array[], int n)
{
for (int gap = n / 2; gap > 0; gap /= 2)
{
for (int i = gap; i < n; i += 1)
{
int temp = array[i];
int j;
for (j = i; j >= gap && array[j - gap] > temp; j -= gap)
{
array[j] = array[j - gap];
}
array[j] = temp;
}
}
}
void printArray(int array[], int size)
{
int i;
cout <<"\t";
for (i = 0; i < size; i++)
cout <<" " << array[i] << " ";
cout << endl;
}
int main()
{
int data[10];
cout <<"\n\n";
cout << "\tShell Sort in C++";
cout <<"\n\n";
for (int a=0; a<10; a++) {
cout << "\tEnter item value number " <<a+1 <<" : ";
cin >> a[data];
}
cout <<"\n\n";
cout << "\tUnSorted array: \n";
cout <<"\n\n";
cout <<"\t";
for (int a=0; a<10; a++) {
cout <<" " <<a[data] <<" ";
}
cout <<"\n\n";
int size = sizeof(data) / sizeof(data[0]);
shellSort(data, size);
cout << "\tSorted array: \n";
cout <<"\n\n";
printArray(data, size);
}
No comments:
Post a Comment