ProAnswers.org

algorithm Binary Tree Traversal

algorithm Binary Tree Traversal

Preorder Traversal:

						1
					
						2
					
						3
					
						4
					
						5
					
						6
					
						7
				
				
					
						
							void preorder(tree *root){
						
							    if(root != NULL){
						
							        printf("%d", root->data);
						
							        preorder(root->left);
						
							        preorder(root->right);
						
							    }
						
							}
					
				
			
		
	



Inorder Traversal:




	
		 
	
		
			
				
					
						1
					
						2
					
						3
					
						4
					
						5
					
						6
					
						7
				
				
					
						
							void inorder(tree *root){
						
							    if(root != NULL){
						
							        inorder(root->left);
						
							        printf("%d", root->data);
						
							        inorder(root->right);
						
							    }
						
							}
					
				
			
		
	



Postorder Traversal:



 


	
		
			
				1
			
				2
			
				3
			
				4
			
				5
			
				6
			
				7
		
		
			
				
					void postorder(tree *root){
				
					    if(root != NULL){
				
					        postorder(root->left);
				
					        postorder(root->right);
				
					        printf("%d", root->data);
				
					    }
				
					}