Здесь отсутствует очистка памяти из-под нелинейного списка,подскажите,пожалуйста,как ее добавить

#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <map>
using namespace std;
int i = 0;
struct List
{
char* info = new char[100];
List* left;
List* right;
} *root;
void Add(char* a, List** node)
{
if ((*node) == NULL)
{
(*node) = new List;
strncpy((*node)->info, a, 100);
(*node)->left = (*node)->right = NULL;
return;
}
if (strcmp(a, (*node)->info) < 0)
{
Add(a, &(*node)->right);
}
else
{
Add(a, &(*node)->left);
}
}
void Show(List* node)
{
if (node == NULL) return;
cout << node->info << endl;
Show(node->left);
Show(node->right);
}
void FindA(List* node)
{
if (node->info[0] == 'a')
i++;
if (node->left != NULL)
{
FindA(node->left);
}
if (node->right != NULL)
{
FindA(node->right);
}
}
int main()
{
int n;
char* info = new char[100];
cout << ("Enter quantity of elements : ");
cin >> n;
for (int i = 0; i < n; i++) {
cout << "Enter element (sequence of characters) " << i + 1 << " : ";
cin >> info;
Add(info, &root);
}
cout << "Tree: " << endl;
Show(root);
FindA(root);
cout << i << " records starts from 'a'";
return 0;
}

Ответы (0 шт):