struct node
{
int data;
int data1;
int data2;
struct node* left;
struct node* right;
};
struct node** stack;
int curr = -1;
void push(struct node* node)
{
++curr;
stack[curr] = node;
}
struct node* pop()
{
return stack[curr--];
}
void visit(struct node* curr)
{
printf("%d ",curr->data);
}
void preOrderiter(struct node* root)
{
printf("*************\n");
struct node* tmp = root;
while(curr != -1 || tmp)
{
while(tmp)
{
push(tmp);
visit(tmp);
tmp = tmp->left;
}
tmp = pop();
tmp = tmp->right;
}
printf("*************\n");
}
void inOrderiter(struct node* root)
{
printf("*************\n");
struct node* tmp = root;
while(curr != -1 || tmp)
{
while(tmp)
{
push(tmp);
tmp = tmp->left;
}
tmp = pop();
visit(tmp);
/*if(!tmp->right)
{
printStack();
}
else*/
tmp = tmp->right;
}
printf("*************\n");
}
int main()
{
stack = malloc(10*sizeof(struct node*));
}
Subscribe to:
Post Comments (Atom)
Blog Archive
-
▼
2009
(46)
-
▼
December
(16)
- Insert Ignore and Replace in MySql
- mysql command prompt paging options
- mysql command prompt auto completion
- Oracle trigger question
- Finding whether a number is blessed or not
- Generating readable assembly with gcc
- Brace matching : Flex Builder
- Finding which place belongs to which district usin...
- Iterative/Non-recursive version of pre order/in or...
- C Dictionary
- A whiteboard built using Flex/PHP/MySql
- Maximum contiguous subarray problem
- Passing array parameters in Java and C
- Grep for space and new line
- Quick Sort in C by Kernighan Ritchie
- A simple hash implementation in C
-
▼
December
(16)
No comments:
Post a Comment