Toshkent Axborot Texnologiyalari Universiteti Samarqand filliali Kompyuter Injinering fakulteti
Dasturiy injinering yo’nalishi
Malumotlar Tuzilmasi va Algoritmlar fanidan
MUSTAQIL ISH – 8
Bajardi: Oltiboyev J
Tekshirdi: Abduvoitov A
Samarqand 2021
14. Binar daraxtning barcha oraliq tugunlari yozuvini chop etuvchi dastur ishlab chiqing.
#include
using namespace std;
struct node {
int info;
node *l, *r;
};
void push(int a, node **t) {
if ((*t) == NULL) {
(*t) = new node;
(*t)->info = a;
(*t)->l = (*t)->r = NULL;
return;
}
if (a > (*t)->info)
push(a, &(*t)->r);
else
push(a, &(*t)->l);
}
void printLeaf(node *t)
{
if ( (t->l == nullptr) && (t->r == nullptr) )
cout << t->info << "\n";
else
{
if (t->l) printLeaf(t->l);
if (t->r) printLeaf(t->r);
}
}
Dostları ilə paylaş: |