Что нужно добавить, чтобы отсортированные элементы были другого цвета? - вопрос №3447978

#include <iostream>
#include <time.h>
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#include <unistd.h>

using namespace std;
void swap(int &x, int &y)
{
int t=x;
x=y;
y=t;
}
void show(int a[],int n,int pos, int elem,HANDLE handle)
{
system(«cls»);
for (int i=0; i<n; i++)
{
if(i==pos)
{
SetConsoleTextAttribute(handle, (WORD) ((13 << 1) | 15));
printf("%8i",elem);
printf("\n");
SetConsoleTextAttribute(handle, (WORD) ((0 << 0) | 15));
}
else {
printf("%4i",a[i]);
printf("\n");

}
}
Sleep(150);
}

int main()
{
HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);
int n,k=0;
printf(«Vvedite chislo elementov massiva — »);
scanf("%d",&n);
int a[n];
srand(time(0));
for(int i=0; i<n; i++)
{
a[i]=rand()%101-37;
printf("%d ",a[i]);
printf("\n");
}
system(«pause»);
show(a,n,-1,0,handle);
for(int i=1; i<n; i++)
{
int t=a[i];
show(a,n,i,t,handle);
int j=i-1;
while(j>=0 && a[j]>t)
{
a[j+1]=a[j];
show(a,n,j,t,handle);
j--;
k++;
}
a[j+1]=t;
show(a,n,-1,0,handle);
}
printf("\n");
for(int i=0; i<n; i++)
{
printf("%d ",a[i]);
}
}
23.09.19
0 ответов
Ответов пока нет
Посмотреть всех экспертов из раздела Технологии > C/C++
Пользуйтесь нашим приложением Доступно на Google Play Загрузите в App Store