Trees - CSC2100A Tutorial Trees Spring 2006/2007 1 CSC2100A...

Info iconThis preview shows pages 1–7. Sign up to view the full content.

View Full Document Right Arrow Icon
CSC2100A Spring 2006-2007 1 CSC2100A Tutorial Trees Spring 2006/2007
Background image of page 1

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

View Full DocumentRight Arrow Icon
CSC2100A Spring 2006-2007 2 Trees - overview •B ina r y t ree – Degree of tree is 2 struct BinaryNode { Objectelement; BinaryNode *left; BinaryNode *rightChild; }; // pseudocode
Background image of page 2
CSC2100A Spring 2006-2007 3 Trees - traversal •P r e o r d e r template <class Comparable> void BinarySearchTree<Comparable>::preorder( BinaryNode<Comparable> *t ) const { if( t != NULL ) { cout << t->element << endl; preorder( t->left ); preorder( t->right ); } }
Background image of page 3

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

View Full DocumentRight Arrow Icon
CSC2100A Spring 2006-2007 4 Trees - traversal •I n o r d e r template <class Comparable> void BinarySearchTree<Comparable>::Inorder( BinaryNode<Comparable> *t ) const { if( t != NULL ) { Inorder( t->left ); cout << t->element << endl; Inorder( t->right ); } }
Background image of page 4
CSC2100A Spring 2006-2007 5 Trees - traversal •P o s t o r d e r template <class Comparable> void BinarySearchTree<Comparable>::postorder( BinaryNode<Comparable> *t ) const { if( t != NULL ) { postorder( t->left ); postorder( t->right ); cout << t->element << endl; } }
Background image of page 5

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

View Full DocumentRight Arrow Icon
CSC2100A Spring 2006-2007 6 Trees - traversal •P reo rde r A B D G H E C F I (Tips: first time) •Ino r G D H B E A F I C (Tips: second time) •Po s to r G H D E B I F C A (Tips: last time) A B C D E F I G H
Background image of page 6
Image of page 7
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 12/28/2010 for the course CSC CSC1110 taught by Professor Cjyuan during the Fall '06 term at CUHK.

Page1 / 24

Trees - CSC2100A Tutorial Trees Spring 2006/2007 1 CSC2100A...

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online