Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- {
- Node *x = new Node();
- x = root;
- if(root==NULL) {
- cout << "The heap is empty" << endl;
- return;
- }
- if(decider==1)
- {
- cout << "Printing Binomial Heap..." << endl;
- while(x!=NULL)
- {
- cout << "Binomial Tree, B" << x->degree << endl;
- int i=0;
- Node *t = new Node();
- t = x;
- vector <Node*> level;
- vector <Node*> children;
- while(i<=x->degree) {
- cout << "Level " << i << " : ";
- if(i==0) {
- cout << x->key << endl;
- i++;
- continue;
- }
- else if(i==1) {
- t = t->child;
- Node *n = new Node(t->key, t->degree, t->parent, t->child, t->sibling);
- while(n!=NULL) {
- level.push_back(n);
- cout << n->key << " ";
- if(n->child!=NULL) children.push_back(n->child);
- n = n->sibling;
- }
- cout << endl;
- level.clear();
- level = children;
- children.clear();
- i++;
- continue;
- }
- for(auto y: level) {
- Node *n = new Node(y->key, y->degree, y->parent, y->child, y->sibling);
- while(n!=NULL) {
- cout << n->key << " ";
- if(n->child!=NULL) children.push_back(n->child);
- n = n->sibling;
- }
- }
- i++;
- level.clear();
- level = children;
- children.clear();
- cout << endl;
- }
- x = x->sibling;
- }
- }
- }
Add Comment
Please, Sign In to add comment