void flatten(node *node, int a[]){
int pos = 0;
if(node){
flatten(node->pleft,a);
a[pos++] = node->data;
flatten(node->pright,a);
}
}
void flatten(node *node, int a[]){
static int pos = 0;
if(node){
flatten(node->pleft,a);
a[pos++] = node->data;
flatten(node->pright,a);
}
}
void flatten(node *node, int a[]){
int pos = 0;
flattenHelper(node, a, &pos);
}
void flattenHelper(node *node, int a[], int *pos){
if(node){
flattenHelper(node->pleft,a, pos);
a[(*pos)++] = node->data;
flattenHelper(node->pright,a, pos);
}
}
void flatten(node *node, int a[], int pos){
int pos;
if(node == NULL)
return pos; // pos get the position of the last node
pos = flatten(node->pleft,a, pos); //go to left subtree until null
a[pos] = node->data; //write in the array at the position
pos = flatten(node->pright,a, pos); // go to right subtree
}
}
int flatten(node *node, int a[], int pos){
if(node == NULL)
return pos;
pos = flatten(node->pleft,a, pos);
a[pos] = node->data;
pos = flatten(node->pright,a, pos);
return pos;
}
int flatten(node *node, int a[], int pos){
if(node == NULL)
return pos;
pos = flatten(node->pleft,a, pos + 1); //a[0] would be lost, so starts in a[1]
a[pos] = node->data;
pos = flatten(node->pright,a, pos + 1);
return pos;
}
a[pos++] = node->data;
Title | # Comments | Views | Activity |
---|---|---|---|
Open a Text Editor from the Command Line Programatically using C# | 3 | 70 | |
Detect CR LF to each line | 12 | 135 | |
AWS and JSON: Best JSON editor for creating CloudFormation Templates, etc. ? | 3 | 83 | |
Using popen() and gunzip() to open file in HTTPServer | 6 | 10 |
Join the community of 500,000 technology professionals and ask your questions.
Connect with top rated Experts
9 Experts available now in Live!