Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include <stdlib.h>
- #include <cstdio>
- #include <iostream>
- using namespace std;
- class Making
- {
- public:
- void making(int *arr,int n)
- {
- for (int i = 0; i < n; i++)
- {
- arr[i] = rand() % 10;
- }
- for (int i = 0; i<n; i++)
- {
- cout << arr[i] << " ";
- }
- }
- };
- class Shell : Making
- {
- public:
- int n;
- void SortingByShell(int *arr,int n)
- {
- int d = n/2;//шаг (вилка) для сравнения элементов
- int temp;//временная переменная для изменения позиций элементов
- int k = 2;//переменная,которая задает длинну цикла
- int j = 0;// переменная для учета границы массива,увеличивается соотв. d
- #pragma region Shell sorting
- while (d != 0)
- {
- for (int i = 0; i < n/k-j ; i++)
- {
- if (arr[i] > arr[i + d])
- {
- temp = arr[i];
- arr[i] = arr[i + d];
- arr[i + d] = temp;
- }
- if (i > d && arr[i]<arr[i-d])
- {
- temp = arr[i];
- arr[i] = arr[i - d];
- arr[i - d] = temp;
- }
- }
- d =(d / 2);
- k=1;
- j = d;
- }
- #pragma endregion
- cout << endl;
- cout << "after Shell sorting:" << endl;
- for(int i=0;i<n;i++)
- {cout << arr[i] << " ";}
- #pragma region insert_sorting_(d=1)
- for (int i = 0; i < n-1; i++)
- {
- for (int i = 0; i < n - 1; i++)
- {
- if (arr[i] > arr[i + 1])
- {
- temp = arr[i];
- arr[i] = arr[i + 1];
- arr[i + 1] = temp;
- }
- }
- }
- #pragma endregion
- }
- void show(int *arr,int n)
- {
- cout << endl;
- cout << "sorting achivied:" << endl;
- for (int i = 0; i < n; i++)
- {
- cout << arr[i] << " ";
- }
- }
- };
- int main()
- {
- int n;
- cout << "type size of array" << endl;
- cin >> n;
- int *arr = new int[n];
- Making Makinging;
- Makinging.making(arr,n);
- Shell shelling;
- shelling.SortingByShell(arr,n);
- shelling.show(arr,n);
- system("Pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement