-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFibonaciheap.h
84 lines (76 loc) · 2.08 KB
/
Fibonaciheap.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#ifndef FIB_HEAP11
#define FIB_HEAP11
#include <stdio.h>
#include <iostream>
#include <list>
#include <vector>
#include <map>
#include <queue>
#include <string>
using namespace std;
template <class type>
class Fnode
{
int No_of_marks;//No of marks in the heap (children)
bool marked;//true if Root is marked
type value;
public:
list< Fnode<type>* > children;
Fnode(type v,bool mark=false):value(v)
{
marked=mark;
}
~Fnode()
{
for(typename list<Fnode<type>* >::iterator itr=children.begin();itr!=children.end();itr++)
delete *itr;
}
type getvalue() {return value;}
void Mark(){ marked=true;}
void Unmark() { marked=false;}
bool ismarked() {return ismarked;}
size_t rank() {return children.size();}
size_t order() {return children.size();}
bool operator<(const Fnode<type> & x)
{ return children.size() < x.children.size();
}
bool operator>(const Fnode<type> & x)
{ return children.size() > x.children.size();
}
bool operator<=(const Fnode<type> & x)
{ return children.size() <= x.children.size();
}
bool operator>=(const Fnode<type> & x)
{ return children.size() >= x.children.size();
}
void printheap(string space)
{
cout << space << "Order: " << order() << " Value: " << getvalue() << endl;
for(typename list<Fnode<type>*>::iterator itr=children.begin();
itr!=children.end();
itr++)
{ cout << space << "-----------Children------------"<<endl;
(*itr)->printheap(string(space+" "));
cout << space << "_______________________________"<<endl;
}
}
};
template <class type,class objects>
class Fibonacciheap
{
Fnode<type>* top_node;
list< Fnode<type>* > nodes;
public:
objects func_object;
Fibonacciheap();
~Fibonacciheap();
void insert(type value);
type top();
void delete_min();
void printHeap(ostream& cout=cout);
private:
void update_top();
Fnode<type>* LinkingOperation(Fnode<type>* a,Fnode<type>* b);
};
#include "fibheap.tpp"
#endif