# gameTrees_quad - General Trees Game Trees General Trees and...

This preview shows pages 1–3. Sign up to view the full content.

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: General Trees Game Trees General Trees and Game Trees ENGI 4892: Data Structures Andrew Vardy Faculty of Engineering & Applied Science Memorial University of Newfoundland June 30, 2011 General Trees Game Trees General Trees A general tree has no restriction on the number of children per node. We can represent a node in a general tree by using two pointers in addition to the item eld: childPtr : A pointer to the rst of the node's children Set to NULL if the node has no children siblingPtr : A pointer to the next sibling (the next child of this node's parent) Set to NULL if the node is the last (rightmost or only) of its parent's children General Trees Game Trees For example, the tree on the left is represented by the structure on the right: General Trees Game Trees Traversals Pre- and postorder traversals are implemented in a slightly di erent manner than for binary trees. A preorder traversal appears quite similar. v o i d p r e O r d e r ( N o d e * n o d e ) { if ( n o d e != N U L L ) { // V i s i t t h i s n o d e ( p r i n t i t ) c o u t << node- > i t e m << e n d l ; p r e O r d e r ( node- > c h i l d P t r ) ; p r e O r d e r ( node- > s i b l i n g P t r ) ; } } General Trees Game Trees For a postorder traversal of a binary tree, two recursive calls were made before visiting the node itself (one for each subtree).made before visiting the node itself (one for each subtree)....
View Full Document

## This note was uploaded on 10/23/2011 for the course ENCS ENCS5 taught by Professor Abdelsalam during the Spring '10 term at Birzeit University.

### Page1 / 4

gameTrees_quad - General Trees Game Trees General Trees and...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online