mirror of
https://github.com/TheAlgorithms/C-Plus-Plus.git
synced 2026-02-04 02:56:40 +08:00
rename Sorting -> sorting (#653)
This commit is contained in:
45
sorting/Shell Sort.cpp
Normal file
45
sorting/Shell Sort.cpp
Normal file
@@ -0,0 +1,45 @@
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
|
||||
int main()
|
||||
{
|
||||
int size = 10;
|
||||
int array[size];
|
||||
// Input
|
||||
cout << "\nHow many numbers do want to enter in unsorted array : ";
|
||||
cin >> size;
|
||||
cout << "\nEnter the numbers for unsorted array : ";
|
||||
for (int i = 0; i < size; i++)
|
||||
{
|
||||
cin >> array[i];
|
||||
}
|
||||
|
||||
// Sorting
|
||||
for (int i = size / 2; i > 0; i = i / 2)
|
||||
{
|
||||
for (int j = i; j < size; j++)
|
||||
{
|
||||
for (int k = j - i; k >= 0; k = k - i)
|
||||
{
|
||||
if (array[k] < array[k + i])
|
||||
{
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
int temp = array[k + i];
|
||||
array[k + i] = array[k];
|
||||
array[k] = temp;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Output
|
||||
cout << "\nSorted array : ";
|
||||
for (int i = 0; i < size; ++i)
|
||||
{
|
||||
cout << array[i] << "\t";
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user