Guest User

Untitled

a guest
Aug 5th, 2021
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. struct Node {
  4. string key;
  5. vector<Node*> child;
  6. bool locked=false;
  7. Node* Parent;
  8. int lockedDes=0;
  9. };
  10. Node* newNode(string value)
  11. {
  12. Node* nNode = new Node;
  13. nNode->key = value;
  14. return nNode;
  15. }
  16.  
  17. Node* BuildChildTree(Node* parent,string* A,int n,int k,int ind){
  18. for (int i = 1; i <=k; i++) {
  19. Node* x= newNode(A[ind+i]);
  20. parent->child.push_back(x);
  21. }
  22. return parent;
  23. }
  24.  
  25. void BuildKaryTree(string* A, int n, int k,int ind)
  26. {
  27. int h = (int)ceil(log((double)n * (k - 1) + 1)/ log((double)k));
  28. for (int i = 1; i <=k; i++) {
  29. Node* x= newNode(A[ind+i]);
  30. nNode->child.push_back(x);
  31. }
  32. for(auto it: nNode->child){
  33. BuildChildTree(it,A,n,k,ind+k);
  34. }
  35. }
  36. int main()
  37. {
  38. int k = 2, n = 10;
  39. int ind=0;
  40. string preorder[] = {"world","asia","africa","china","india","south","egypt"};
  41. Node* root = newNode("world");
  42. BuildKaryTree(root,preorder, n, k,ind);
  43. // postord(root, k);
  44. cout << endl;
  45. return 0;
  46. }
Advertisement
Add Comment
Please, Sign In to add comment