ника5010
01.01.2020 08:17

переделать программу под задание(С++) #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

Нажмите на рекламу ниже и сразу увидите ответ
↓
Популярные вопросы:
Ответ:
yanachor25
11.04.2022 06:56
1. Вот так это пишется с функцией

// PascalABC.NET 3.1, сборка 1200 от 13.03.2016
function IsPrime(n:integer):boolean;
begin
  if n<4 then Result:=True
  else begin
    var found:= (n mod 2 = 0);
    var p:=3;
    while (not found) and (sqr(p)<=n) do
      begin
      found:=(n mod p = 0);
      p+=2
      end;
    Result:=not found
    end
end;

begin
  Writeln('k=',ArrRandom(ReadInteger('n='),1,999).Println.
    Where(x->IsPrime(x)).Count)
end.

Тестовое решение:
n= 10
401 828 780 444 694 965 23 341 673 875
k=3

2. А вот так это пишется с процедурой

// PascalABC.NET 3.1, сборка 1200 от 13.03.2016
procedure IsPrime(n:integer; var res:boolean);
begin
  if n<4 then res:=True
  else begin
    var found:= (n mod 2 = 0);
    var p:=3;
    while (not found) and (sqr(p)<=n) do
      begin
      found:=(n mod p = 0);
      p+=2
      end;
    res:=not found
    end
end;

begin
  var a:=ArrRandom(ReadInteger('n='),1,999); a.Println;
  var k:=0;
  var prime:boolean;
  foreach var e in a do begin
    IsPrime(e,prime);
    if Prime then Inc(k)
    end;
  Writeln('k=',k)
end.

Тестовое решение:
n= 12
199 43 71 365 417 904 170 212 694 103 161 689
k=4
0,0(0 оценок)
Ответ:
dasha1975
31.05.2023 03:24
// тестировалось на C#.Net Framework 4.5
using System;

class Program
{
    static void Main()
    {
        int x1 = 2, y1 = 1;
        int x2 = 6, y2 = 5;
        int x3 = 10, y3 = 1;

        var a = Distance(x2, y2, x3, y3);
        var b = Distance(x1, y1, x3, y3);
        var c = Distance(x2, y2, x1, y1);

       
        Console.WriteLine("S = {0}", Square(a, b, c));
        Console.ReadKey();
    }

    //растояние между точками
    static double Distance(int x1, int y1, int x2, int y2)
    {
        return Math.Sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1));
    }

    //формула герона
    static double Square(double a, double b, double c)
    {
        var p = (a + b + c) / 2;
        return Math.Sqrt(p * (p - a) * (p - b) * (p - c));
    }

    // теорема косинусов
    static double Angle(double a, double b, double c)
    {
        return Math.Acos((b * b + c * c - a * a) / (2 * b * c));
    }

    static bool IsAcuteAngel(double alpha)
    {
        return alpha < Math.PI / 2;
    }
}
0,0(0 оценок)
Полный доступ
Позволит учиться лучше и быстрее. Неограниченный доступ к базе и ответам от экспертов и ai-bota Оформи подписку
logo
Начни делиться знаниями
Вход Регистрация
Что ты хочешь узнать?
Спроси ai-бота