Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions sem1/test1/test2.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#include <iostream>
#include <time.h>
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] {};
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

не самое лучшее сокращение

cout << "Enter item values" << endl;
for (int i = 0; i < amount; i++)
{
cin >> arr[i];
}

srand(time(NULL));
for (int i = 0; i < amount; i++)
{
discharge = rand() % 32 + 11;

}

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;
}