-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathheap.cpp
More file actions
66 lines (62 loc) · 1.04 KB
/
heap.cpp
File metadata and controls
66 lines (62 loc) · 1.04 KB
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
struct node{
int key;
node* father, next, last, right, left;
};
class heap{
public:
heap();
~heap();
bool insert(key);
bool delete(key);
void print();
private:
node* root, end, start, donde;
};
node* heap::newNode(key){
node *p=new node;
p->father=NULL;
p->next=NULL;
p->last=NULL;
p->right=NULL;
p->left=NULL;
return p;
}
bool heap::insert(key){
node* target=newNode();
insertList(target);
if(root==NULL){
root=target;
donde=target;
return true;
}
if (!donde->left){
donde->left=target;
donde->next=target;
}else{
donde->right=target;
target->father=donde;
donde=donde->next;
}
}
//father, left ,right , last, next
void heap::swap(node *a,node *b){
node* aux = a->father;
a->father=b->father;
if(b->left==a){
b->
}
}
void heap::rise(node *target){
while(target->father && target->father-key>target->key){
}
}
void heap::insertList(node *target){
if(start){
end->next=targert;
target->last=end;
end=target;
}else{
start=target;
end=target;
}
}