From 7b86b6ba5fdb5f7f36b79a92010e984566ca13ef Mon Sep 17 00:00:00 2001 From: vj586da Date: Thu, 2 Dec 2021 16:17:47 +0100 Subject: [PATCH] almost final --- a4/program.c | 90 +++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 68 insertions(+), 22 deletions(-) diff --git a/a4/program.c b/a4/program.c index 4b20c87..6771bfa 100644 --- a/a4/program.c +++ b/a4/program.c @@ -1,67 +1,113 @@ #include #include #include +#include -#define SIZE 20 +#define SIZE 100 int checkMinHeap(const long* arr, const int size){ + //printf("size: %d\n",size); if(size == 1){ return 1; } + if(size == 2){ + if(arr[0] < arr[1]){ + return 1; + }else { + return -1; + } + } for (int i = 0; i<=(size-2)/2; i++) { - if(arr[2*i] < arr[i]) return -1; - if(arr[2*i+1] < arr[i]) return -1; + if(arr[2*i+1] < arr[i]) return -1; + if(arr[2*i] < arr[i]) return -1; } return 1; } -long int* strToInt(const char* chArr){ +long int* strToInt(const char* chArr, int* counter){ int j = strlen(chArr); //int i = 0; - int counter=0; - //printf("dlength %d\n",j/2-1); + *counter=0; + //printf("dlength %d\n",j); long int* tmp = (long int*)calloc(j,sizeof(long)); char* pEND; for(int i=0; i