Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //shellSort.cpp
- void ShellSort(int n, int mass[])
- {
- int i, j, step;
- int tmp;
- for (step = n / 2; step > 0; step /= 2)
- {
- for (i = step; i < n; i++)
- {
- tmp = mass[i];
- for (j = i; j >= step; j -= step)
- {
- if (tmp < mass[j - step])
- {
- mass[j] = mass[j - step];
- }
- else
- {
- break;
- }
- }
- mass[j] = tmp;
- }
- }
- }
- //main.cpp
- #include <iostream>
- void ShellSort(int n, int mass[]);
- int main()
- {
- int n;
- std::cout << "Input number of elements: ";
- std::cin >> n;
- int *mass = new int[n];
- std::cout << "---- Shell sort ----\nInput the array elements:\n";
- for (int i = 0; i < n; i++)
- {
- std::cin >> mass[i];
- }
- ShellSort(n, mass);
- std::cout << "Sorted array:\n";
- for (int i = 0; i < n; i++)
- {
- std::cout << mass[i] << " ";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement