From f79dbeda74c6844c3b40b67885da6612f50b1b22 Mon Sep 17 00:00:00 2001 From: Maksym Malko Date: Fri, 4 Dec 2020 06:41:54 +0000 Subject: [PATCH] =?UTF-8?q?=D0=98=D0=B7=D0=BC=D0=B5=D0=BD=D0=B8=D1=82?= =?UTF-8?q?=D1=8C=20'a3/program.c'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- a3/program.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/a3/program.c b/a3/program.c index 919caa9..59c50e7 100644 --- a/a3/program.c +++ b/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);