From 8062880277992c0934896cdd34bc18be3e450842 Mon Sep 17 00:00:00 2001 From: Anton Chernikov Date: Sat, 29 Sep 2018 13:16:37 +0300 Subject: [PATCH 1/2] Added task test2 --- sem1/test1/test2.cpp | 45 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 sem1/test1/test2.cpp diff --git a/sem1/test1/test2.cpp b/sem1/test1/test2.cpp new file mode 100644 index 0000000..854c9d7 --- /dev/null +++ b/sem1/test1/test2.cpp @@ -0,0 +1,45 @@ +#include +using namespace std; + +void display(int, int n[]); + +int main() +{ + cout << "Enter amount of number" << endl; + int amount = 0; + cin >> amount; + int *arr = new int[amount] {}; + cout << "Enter item values" << endl; + for (int i = 0; i < amount; i++) + { + cin >> arr[i]; + } + + cout << "Before - "; + display(amount, arr); + + int current = 0; + int selIndex = 0; + for (int i = 2; i < amount; i += 2) + { + current = arr[i]; + for (selIndex = i - 2; selIndex >= 0 && arr[selIndex] > current; selIndex -= 2) + { + arr[selIndex + 2] = arr[selIndex]; + } + arr[selIndex + 2] = current; + } + + cout << "After - "; + display(amount, arr); + delete[] arr; +} + +void display(int length, int num[]) +{ + for (int i = 0; i < length; i++) + { + cout << num[i] << " "; + } + cout << endl; +} From 1ed6abb797f1ce8f77c72311da240c2577de1a0b Mon Sep 17 00:00:00 2001 From: Anton Chernikov Date: Sat, 29 Sep 2018 13:20:22 +0300 Subject: [PATCH 2/2] Added task test2 --- sem1/test1/test2.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/sem1/test1/test2.cpp b/sem1/test1/test2.cpp index 854c9d7..e7f806f 100644 --- a/sem1/test1/test2.cpp +++ b/sem1/test1/test2.cpp @@ -1,4 +1,5 @@ #include +#include using namespace std; void display(int, int n[]); @@ -15,6 +16,13 @@ int main() cin >> arr[i]; } + srand(time(NULL)); + for (int i = 0; i < amount; i++) + { + discharge = rand() % 32 + 11; + + } + cout << "Before - "; display(amount, arr);