second commit

This commit is contained in:
Valér Jakubčo 2021-12-02 03:31:27 +01:00
parent 9a5bc0137a
commit 9258ce3eac

View File

@ -5,6 +5,9 @@
#define SIZE 20
int checkMinHeap(const long* arr, const int size){
if(size == 1){
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;
@ -15,40 +18,33 @@ int checkMinHeap(const long* arr, const int size){
long int* strToInt(const char* chArr){
int j = strlen(chArr);
//int i = 0;
int counter=0;
//printf("dlength %d\n",j/2-1);
long int* dArr = (long int*)calloc(j,sizeof(long));
long int* tmp = (long int*)calloc(j,sizeof(long));
char* pEND;
for(int i=0; i<j; i++){
dArr[i] = strtol(chArr, &pEND, 10);
tmp[i] = strtol(chArr, &pEND, 10);
//printf("%ld \n", dArr[i]);
if(dArr[i] == 0) break;
if(tmp[i] == 0) break;
counter++;
chArr = pEND;
}
/* for(int i = 0; i<j/2-1; i++){
printf("%ld ", dArr[i]);
}*/
printf("counter %d\n", counter);
long* dArr = (long*)calloc(counter, sizeof(long));
for(int i; i < counter; i++){
dArr[i] = tmp[i];
}
free(tmp);
return dArr;
}
void print_tree(const long* arr){
int offset = 0;
int j =0;
while(j != sizeof(&arr)/sizeof(arr[0])){
for (int i = 0; i < offset; i++){
printf(" ");
}
printf("%ld\n",arr[j]);
offset+=1;
for (int i = 0; i < offset; i++){
printf(" ");
}
printf("%ld\n",arr[j*2+1]);
for (int i = 0; i < offset; i++){
printf(" ");
}
printf("%ld\n",arr[j*2+2]);
j++;
offset+=1;
long size = sizeof(&arr)/sizeof(arr[0]);
for(int i = 0; i < size; i++){
printf("%ld\n", arr[i]);
}
}