Watch the //!! comments
Code:
#include <iostream>
using namespace std;
struct elem {
int key1;
elem *next;
} *start, *start1, *last, *last1;
struct ELEM {
int key2, pole;
ELEM *left, *right;
} *root1, *root2;
void push(int n) //adding an element in queue(FIFO)
{
elem *p = last;
last = new elem;
last->key1 = n;
last->next = NULL;
if (p != NULL)
p->next = last;
if (start == NULL) {
start = last;
}
}
void push1(int n) // adding an element in queue(FIFO)
{
elem *p = last1;
last1 = new elem;
last1->key1 = n;
last1->next = NULL;
if (p != NULL)
p->next = last1;
if (start1 == NULL) {
start1 = last1;
}
}
void addTREE(int n, ELEM * &t) // creating a binary tree
{
if (t == NULL) {
t = new ELEM;
t->key2 = n;
t->left = t->right = NULL;
} else {
if (t->key2 < n)
addTREE(n, t->right);
else
addTREE(n, t->left);
}
}
int search_recurs(struct elem *p, int n)
{
if (start == NULL) {
return 0;
} else {
if ((p->key1 < n) && (p->next == NULL)) {
return 0;
} else {
if (p->key1 == n)
return 1;
else {
if (p->key1 < n)
search_recurs(p->next, n);
else {
return 0;
}
}
}
}
}
ELEM *search_iter(ELEM * t, int k) // Searching in binary tree
{
while ((t != NULL) && (t->key2 != k))
if (t->key2 < k)
t = t->right;
else
t = t->left;
return t;
}
void Available(ELEM * t, int n)
{
if ((t != NULL) && (t->key2 == n)) {
t->pole = 0;
Available(t->left, n);
Available(t->right, n);
}
}
void preorder(ELEM * t)
{
if (t) {
cout << t->key2 << " ";
preorder(t->left);
preorder(t->right);
}
}
void Traverse(elem * p)
{
while (p->next != NULL) {
cout << p->key1 << " ";
p = p->next;
}
}
int main() //!! Yes, REALLY - main returns int
{
int ch, k, i, NOMER, NR;
do {
int num;
cout << " Menu\n";
cout << "1- Add flying airplanes\n";
cout << "2- Add landed airplanes \n";
cout << "3- Add airplanes for landing\n";
cout << "4- Add airplanes for taking off \n";
cout << "5- Show the tree of landed airplanes\n";
cout << "6- Show the tree of flying airplanes \n";
cout << "7- Show the queue -waiting taking off airplanes\n";
cout << "8- Show the queue –waiting landing airplanes\n";
cout << "9 –Show the condition of particular airplane \n";
cout << "0- END.\n";
cout << "Make your choice : \n";
cin >> ch;
switch (ch) {
case (1):
cout << "\n NOMER : ";
cin >> NOMER;
addTREE(NOMER, root1);
case (2):
cout << "\n NOMER : ";
cin >> NOMER;
addTREE(NOMER, root2);
case (3):
cout << "\n NOMER : ";
cin >> k;
search_iter(root1, k);
push(k);
//pop(k);
Available(root1, k);
case (4):
cout << "\n NOMER : ";
cin >> k;
search_iter(root2, k);
push1(k);
//pop1(k);
Available(root2, k);
case (5):
preorder(root1);
case (6):
preorder(root2);
case (7):
Traverse(start);
case (8):
Traverse(start1);
case (9):
{
cout << "Add a number of particular airplane\n";
cin >> NR;
if (search_recurs(start, NR) != 0)
cout << "\n The airplane is in the queue for landing";
if (search_recurs(start1, NR) != 0)
cout <<
"\n The airplane is in the queue for taking off ";
if (search_iter(root1, NOMER) != NULL) //!! WAS 1
cout << "\n The airplane is in the tree of flying";
if (search_iter(root2, NOMER) != NULL) //!! WAS 1
cout << "\n The airplane is in the tree of landed";
}
}
}
while (ch != 0); //!! MOVED down one }
return 0; //!! Tell the environment we were successful
}
Also note the use of iostream and using namespace std;
Only use a modern compiler which understands these things. Do not try this with some fossil turboc relic from the past.
Oh, one more thing, I only made it COMPILE.
The run-time bugs are still for you to fix.