NODE *__bal(int *a, int n){ int mid = n/2; NODE *temp; if(n<1) return 0; temp = malloc(sizeof(NODE)); temp->data = a[mid]; temp->left = __bal(a, mid); temp->right = __bal(a+mid+1, n-mid-1); return temp; }
int main (int argc, char *argv[]) { int i; int buff[7] = {5, 3, 4, 7, 6, 1, 2}; for (i=0; i<7; i++) { insert_data(buff[i]); // print(root); } int row = -1, col = 0; // __fill(root, &row, &col); // print(root); root = __bal(buff, 7); print(root); /* 오전 수업 printf("--------------------\n"); in_order (root); printf("--------------------\n"); display (root); printf("--------------------\n"); indent_display (root); printf("--------------------\n"); display_2 (root); int (*arr)[10]; arr = __display(root); for (i=0; i<3; i++) { for (j=0; j<10; j++) { if (arr[i][j] == 0) { printf("%4c", ' '); } else { printf("%4d", arr[i][j]); } } printf("\n"); } puts("-------------------------------"); */ return 0; }
void bal(NODE *temp){ int a[100]; int n = 0; __fill(temp, a, &n); root = __bal(a, n); }