Дони1214
02.01.2020 01:47

переделать программу под задание(С++) #include

#include

using namespace std;

struct TREE {

int info, count;

TREE *left, *right;

};

TREE *root=NULL;

int flag=0;

int count=0;

TREE *Search(int info)

{

TREE *current=root;

flag=0;

while(current!=NULL && flag==0)

{

if(info info)

current=current->left;

else if(info>current->info)

current=current->right;

else

flag=1;

}

return current;

}

void Add(TREE **current, int info)

{

if(*current!=NULL)

{

if(info<(*current)->info)

Add(&(*current)->left, info);

else if(info>(*current)->info)

Add(&(*current)->right, info);

else

(*current)->count++;

}

else

{

*current=new TREE;

(*current)->info=info;

(*current)->left=NULL;

(*current)->right=NULL;

(*current)->count=1;

count++;

}

}

void AddLoop(int info)

{

if(root==NULL)

{

root=new TREE;

root->info=info;

root->right=NULL;

root->left=NULL;

root->count=1;

count++;

}

else

{

TREE *current=root;

TREE *parent;

while(current!=NULL)

{

parent=current;

if(info info)

current=current->left;

else if(info>current->info)

current=current->right;

else

{

current->count++;

current=NULL;

}

}

if(info info)

{

current=new TREE;

current->left=NULL;

current->right=NULL;

current->info=info;

current->count=1;

parent->left=current;

count++;

}

else if(info>parent->info)

{

current=new TREE;

current->left=NULL;

current->right=NULL;

current->info=info;

current->count=1;

parent->right=current;

count++;

}

}

}

void Changer(TREE **current, TREE **tmp)

{

if((*current)->right!=NULL)

Changer(&(*current)->right, &(*tmp));

else

{

(*tmp)->info=(*current)->info;

*tmp=*current;

*current=(*current)->left;

}

}

int Delete (TREE **current, int info)

{

int r=0;

if(*current!=NULL)

{

if(info<(*current)->info)

r=Delete(&(*current)->left, info);

else if(info>(*current)->info)

r=Delete(&(*current)->right, info);

else

{

TREE *tmp=*current;

if(tmp->right==NULL)

*current=tmp->left;

else if(tmp->left==NULL)

*current=tmp->right;

else

Changer(&(*current)->left, &tmp);

delete tmp;

count--;

r=1;

}

}

return r;

}

void ShowBackSymmetric(TREE *current, int l)

{

if(current!=NULL)

{

ShowBackSymmetric(current->right, l+1);

for(int i=0; i info << endl;

ShowBackSymmetric(current->left, l+1);

}

}

void Show(TREE *current)

{

if(current!=NULL)

{

Show(current->left);

cout << current->info << "(" << current->count << ")" << "";

Show(current->right);

}

}

void Clear(TREE **current)

{

if(*current!=NULL)

{

Clear(&(*current)->left);

Clear(&(*current)->right);

delete *current;

count--;

if(count==0)

*current=NULL;

}

}

int main()

{

setlocale(LC_ALL,"Russian");

int n, num;

char otv;

do

{

cout << endl << "1. Создать"

<< endl << "2. Добавить"

<< endl << "3. Добавить (цикл)"

<< endl << "4. Удалить"

<< endl << "5. Обратно-симметричный обход"

<< endl << "6. Вывод со счетчиком"

<< endl << "7. Очистить"

<< endl << "0. Выход"

<< endl << " = ";

cin >> otv;

switch(otv)

{

case '1':

cout << endl << "Кол-во элементов = ";

cin >> n;

for (int i=0; i > num;

Add(&root, num);

cout << endl << "Элемент добавлен" << endl;

break;

case '3':

cout << endl << "Введите элемент = ";

cin >> num;

AddLoop(num);

cout << endl << "Элемент добавлен" << endl;

break;

case '4':

if(root!=NULL)

{

cout << endl << "Удаляемый элемент = ";

cin >> num;

if(Delete(&root, num)==1)

cout << endl << "Элемент удален" << endl;

else

cout << endl << "Элемент не найден" << endl;

}

else

cout << endl << "Дерево пустое" << endl;

break;

case '5':

if(root!=NULL)

{

ShowBackSymmetric(root,0);

}

else

cout << endl << "Дерево пустое" << endl;

break;

case '6':

if(root!=NULL)

{

Show(root);

}

else

cout << endl << "Дерево пустое" << endl;

break;

case '7':

Clear(&root);

cout << endl << "Дерево очищено" << endl;

break;

case '0':

break;

default:

cout << endl << "Ошибка" << endl;

break;

}

}while(otv!='0');

cin. get();

}


переделать программу под задание(С++) #include #include using namespace std; struct TREE { int inf

Нажмите на рекламу ниже и сразу увидите ответ
↓
Популярные вопросы:
Ответ:
skalapendra1212
02.03.2023 07:27
// PascalABC.NET 3.0, сборка 1156 от 30.01.2016
function Avg(a:array[,] of integer):real;
begin
  var s:=0; var k:=0;
  foreach var e:integer in a do
    if e>0 then begin s+=e; Inc(k) end;
  if k>0 then Result:=s/k else Result:=1e-100;
end;

begin
  var A:=MatrixRandom(4,4,-50,50); Writeln(A);
  Writeln('Среднее арифметическое положительных равно ',Avg(A):0:3);
  var B:=MatrixRandom(5,5,-30,30); Writeln(B);
  Writeln('Среднее арифметическое положительных равно ',Avg(B):0:3);
  var C:=MatrixRandom(4,5,-25,38); Writeln(C);
  Writeln('Среднее арифметическое положительных равно ',Avg(C):0:3);
end.

Тестовое решение:
[[35,35,5,-47],[14,34,35,-13],[25,-5,35,-29],[-7,10,-12,12]]
Среднее арифметическое положительных равно 24.000
[[-12,-17,-10,19,14],[20,17,-27,-2,16],[-3,-21,30,2,10],[5,-3,-17,-3,18],[0,-26,29,1,-22]]
Среднее арифметическое положительных равно 15.083
[[-5,-11,17,-4,15],[15,17,-24,36,15],[-8,-3,-22,28,-25],[-21,6,12,31,-1]]
Среднее арифметическое положительных равно 19.200
0,0(0 оценок)
Ответ:
anyalogunova1
16.10.2020 05:00
uses crt,graph; type mas=array[1..500] of Pointtype; var gd,gm,i,j,k,n:integer;     a:mas; begin randomize; gd:=0; initgraph(gd,gm,''); for i:=1 to 500 do  begin   a[i].x:=random(getmaxX);   a[i].y:=random(getmaxY);   circle(a[i].x,a[i].y,2);  end; k:=0;n:=0; repeat k:=k+1; delay(200); setcolor(0); for i:=1 to 500 do circle(a[i].x,a[i].y,2); for i:=1 to 500 do  begin   if a[i].y>getmaxY-n-10 then a[i].y:=1   else a[i].y:=a[i].y+3;   if a[i].x<0 then a[i].x:=getmaxX   else a[i].x:=a[i].x-1;  end; setcolor(15); for i:=1 to 500 do circle(a[i].x,a[i].y,2); if k mod 20=0 then  begin   n:=n+1;   line(0,getmaxY-n,getmaxX,getmaxY-n);  end; until keypressed; readln end.
0,0(0 оценок)
Полный доступ
Позволит учиться лучше и быстрее. Неограниченный доступ к базе и ответам от экспертов и ai-bota Оформи подписку
logo
Начни делиться знаниями
Вход Регистрация
Что ты хочешь узнать?
Спроси ai-бота