Изменить 'a3/program.c'
This commit is contained in:
parent
0071dfada2
commit
f79dbeda74
16
a3/program.c
16
a3/program.c
@ -68,12 +68,7 @@ void add(struct heap* h,int value){
|
||||
h->size += 1;
|
||||
h->array[i] = value;
|
||||
// Pozrieme na jeho rodiča
|
||||
int p = parent(i);
|
||||
|
||||
while(h->array[i] < h->array[p]) { // i 0 — мы в корне
|
||||
swap(h->array,i, p);
|
||||
i = parent(i);
|
||||
}
|
||||
}
|
||||
|
||||
void print(struct heap* h,int count_spaces,int index){
|
||||
@ -94,6 +89,15 @@ void print(struct heap* h,int count_spaces,int index){
|
||||
|
||||
}
|
||||
|
||||
void sort(struct heap *h){
|
||||
int i = h->size-1;
|
||||
int p = parent(i);
|
||||
|
||||
while(h->array[i] < h->array[p]) { // i 0 — мы в корне
|
||||
swap(h->array,i, p);
|
||||
i = parent(i);
|
||||
}
|
||||
}
|
||||
|
||||
int main(){
|
||||
int i =0;//index of array
|
||||
@ -110,7 +114,7 @@ int main(){
|
||||
}
|
||||
|
||||
check_heap_property(h);
|
||||
|
||||
sort(h);
|
||||
puts("Je to taka kopa:");
|
||||
|
||||
print(h,0,0);
|
||||
|
Loading…
Reference in New Issue
Block a user