Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- struct Node {
- string key;
- vector<Node*> child;
- bool locked=false;
- Node* Parent;
- int lockedDes=0;
- };
- Node* newNode(string value)
- {
- Node* nNode = new Node;
- nNode->key = value;
- return nNode;
- }
- Node* BuildChildTree(Node* parent,string* A,int n,int k,int ind){
- for (int i = 1; i <=k; i++) {
- Node* x= newNode(A[ind+i]);
- parent->child.push_back(x);
- }
- return parent;
- }
- void BuildKaryTree(string* A, int n, int k,int ind)
- {
- int h = (int)ceil(log((double)n * (k - 1) + 1)/ log((double)k));
- for (int i = 1; i <=k; i++) {
- Node* x= newNode(A[ind+i]);
- nNode->child.push_back(x);
- }
- for(auto it: nNode->child){
- BuildChildTree(it,A,n,k,ind+k);
- }
- }
- int main()
- {
- int k = 2, n = 10;
- int ind=0;
- string preorder[] = {"world","asia","africa","china","india","south","egypt"};
- Node* root = newNode("world");
- BuildKaryTree(root,preorder, n, k,ind);
- // postord(root, k);
- cout << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment