Answer to Question #272508 in C for gcgfxt3

Question #272508

WAP to implement non-recursive pre-order and post-order traversals using

Stack data structure for binary tree.


1
Expert's answer
2021-11-30T18:43:30-0500
#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]);
	}
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS