Basically I'm trying to create a program that outputs a binary tree in the form of X's. If the X doesn't belong it outputs a -. This is what I got so far. Any help would be greatly appreciative as I'm not that advanced and need to do this asap lol.
Code:#include <stdio.h> #include <math.h> #define element 64 void makeTree(int left, int right, char array[][element], int depth, int terminate); void display(char array[][element], int depth); int main() { int row=7, left=0, right, depth, terminate, i, j; char array[row][element]; right = pow(2, row); depth = 0; terminate=row; printf("row %d element %d", row, element); makeTree(left, right, array, depth, terminate); display(array, depth); } void makeTree(int left, int right, char array[][element], int depth, int terminate) { if (depth==terminate) return; else { array[depth][(right+left)/2]='x'; makeTree(left, (right+left)/2, array, depth++, terminate); makeTree((right+left)/2+1, right, array, depth++, terminate); } } void display(char array[][element], int depth){ int i, j; for(i = 0; i < depth; i++){ for(j = 0; j < element; j++){ if(array[i][j] == 'x') printf("%c", array[i][j]); else printf("-"); } printf("\n"); } }



LinkBack URL
About LinkBacks


