Skip to content

Instantly share code, notes, and snippets.

@catharsis96
Created October 12, 2016 13:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save catharsis96/810297dd4b895fd220bef57f308d0e07 to your computer and use it in GitHub Desktop.
Save catharsis96/810297dd4b895fd220bef57f308d0e07 to your computer and use it in GitHub Desktop.
#include <iostream>
using namespace std;
struct CNode
{
int number; // number of node
int data; // some node data
unsigned int nChildCount; // amount of chidren
CNode* pChildren; // pointer to array of child nodes
};
int nn = 0;
int count = 0;
void Zapolnenie(CNode* pNode)
{
pNode->number = nn++;
cout << "Vi v vershine " << pNode->number << "\nDannie uzla ";
cin >> pNode->data;
cout << "How many children? ";
unsigned int l; cin >> l;
if (l > 0)
{
pNode->nChildCount = l;
pNode->pChildren = new CNode[l];
for (int qq = 0; qq < l; ++qq)
{
Zapolnenie(&pNode->pChildren[qq]);
}
}
else
{
pNode->nChildCount = 0;
pNode->pChildren = NULL;
++count;
}
}
void Udalenie(CNode* pNode)
{
if (pNode->nChildCount > 0)
{
for (int qq = 0; qq < pNode->nChildCount; ++qq)
{
Udalenie(&pNode->pChildren[qq]);
}
delete[] pNode->pChildren;
}
}
int main()
{
CNode node;
Zapolnenie(&node);
cout << "Kolichestvo list'ev: " << count;
//getch();
Udalenie(&node);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment