d-ary heap














































d-ary heap



d-heap:
            d-heap is generalization of binary heap.it is one kind f advantage in c++.d-heap is a priority queue data structure,a generalization of the binary heap in which the nodes have d children instead of 2,. thus a,binary heap is a 2-heap,and a ternary heap is a 3-heap. 
code for d-ary heap:

#include<iostream>
using namespace std;
class dheap {
public:
 int *a,i,d,n; 
 
 dheap() {
  cout<<"\nEnter d:";
  cin>>d;
  a=new int(n);
 }
 
 int insert() {
 int k=-1,pos;
 char ch;
  do  {
   ++k;
   for(int i=0;i<d;i++) {
   pos=(d*k)+i;
   cout<<"\nEnter Data "<<k<<" :";
   cin>>a[pos];
   cout<<"\nData?[y/n]";
   cin>>ch;
   }
  }while(ch=='y');
}

 int show() {
  cout<<"\nElements:";
  for(i=0;a[i];i++)
   cout<<a[i]<<" ";
  }
};

int main() {
 dheap h;
 h.insert();
 h.show();
}
output:
enter d:2
enter data 0:1
data[y/n]y
enter data 0:3
data[y/n]y
enter data 1:4
data[y/n]y
enter data 1:7
data[y/n]n
elements:1 3 4 7

 

More Articles of Mujibu Rahman:

Name Views Likes
d-ary heap 1049 1

Comments