Created
October 12, 2016 13:49
-
-
Save catharsis96/810297dd4b895fd220bef57f308d0e07 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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