24.12.2012 Views

CSC322 C Programming and UNIX - Department of Computer ...

CSC322 C Programming and UNIX - Department of Computer ...

CSC322 C Programming and UNIX - Department of Computer ...

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Assignment<br />

A binary search tree is either empty, or it consist <strong>of</strong> a node storing a key (the root<br />

<strong>of</strong> the tree), <strong>and</strong> a left <strong>and</strong> right subtree, such that all keys in the left subtree<br />

are smaller than the key in the node, <strong>and</strong> all keys in the right subtree are bigger<br />

– To print a tree in (left-to-right) preorder, you first print the root, then the left<br />

subtree, then the right subtree<br />

– To print a tree in (left-to-right) postorder, you first print the left subtree, then<br />

the right subtree, then the root<br />

– To print a tree in natural order, you first print the left tree, then the root, then<br />

the right tree<br />

Design a data structure for binary search trees with int keys, using dynamic<br />

memory h<strong>and</strong>ling<br />

Implement functions to:<br />

– Insert keys into the tree (ignoring keys already in the tree)<br />

– Print a tree in preorder, natural order, <strong>and</strong> postorder<br />

– Free the memory taken up by the tree<br />

Stephan Schulz 286

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!