WAP to implement non-recursive pre-order and post-order traversals using
Stack data structure for binary tree.
#include<stdio.h>
int arr[100];
int top = 0;
void push(int val){
arr[top] = val;
top++;
}
void pop(){
top --;
}
int peek(){
return arr[top];
}
int main(){
push(10);
push(1);
push(3);
push(4);
int i;
for(i=0; i<top; i++){
printf("%d ",arr[i]);
}
}
Comments
Leave a comment