Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <algorithm>
- using namespace std;
- int main()
- {
- int arr_size;
- cout << "Input the number integers> ";
- cin >> arr_size;
- int* arr = new int[arr_size];
- int i,j;
- string quest;
- //char answ2;
- for (i = 0; i < arr_size; i++) {
- cout << "Input the integer # " << i + 1 << " ";
- cin >> arr[i];
- }
- cout << "Current array: "; //выводим введённый массив
- for (i = 0; i < arr_size; i++) {
- cout << arr[i] << " ";
- }
- int first;
- int second;
- cout << "\nInput bounds of the segment> "; //обозначаем границы сортировки (первая и вторая координаты)
- cin >> first >> second;
- cout << "\nInput an order of sorting (asc/desc)> "; //тип сортировки (asc - по возрастанию, desc - по убыванию)
- cin >> quest;
- first -= 1; //т.к координаты массива начинаются с нуля, отнимаем единицу
- second -= 1;
- j = first;
- i = first;
- if (quest == "desc") { //сортировка пузырьком
- for (j = first; j < second; j++) {
- for (i = first; i < second - (i + 1); i++) {
- if (arr[i] > arr[i + 1]) {
- swap(arr[i], arr[i + 1]);
- }
- }
- }
- }
- if (quest == "asc") { //тоже сортировка пузырьком
- for (j = first; j < second; j++) {
- for (i = first; i < second - (i + 1); i++) {
- if (arr[i] < arr[i + 1]) {
- swap(arr[i], arr[i + 1]);
- }
- }
- }
- }
- for (i = 0; i < arr_size; i++) {
- cout << arr[i] << " ";
- }
- /*cout << "\nContinue? (Y/N)> ";
- cin >> answ2;*/
- return 0;
- }
Add Comment
Please, Sign In to add comment