L13_BinaryTree

L13_BinaryTree - The Binary Tree ADT As we have been doing,...

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

View Full Document Right Arrow Icon
The Binary Tree ADT As we have been doing, we shall define Binary Trees and Tree Nodes to be Abstract Data Types. findMinNode l eftSubt r ee root Page 1 of 16
Background image of page 1

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

View Full DocumentRight Arrow Icon
* public interface TreeNode { public String getNodeKey(); public boolean equalTo(TreeNode N); } public interface BinaryTree { public TreeNode root(); public BinaryTree leftSubtree(); public BinaryTree rightSubtree(); public boolean isEmpty(); public boolean equalTo(BinaryTree t); public BinaryTree insertNode(TreeNode N); public TreeNode findMinNode(); public BinaryTree deleteNode(TreeNode N); } Page 2 of 16
Background image of page 2
Implementation of the Tree Node ADT We consider tree nodes with character strings as keys, and objects as data. public class OrdinaryTreeNode implements TreeNode { private String key; private Object contents; "0123849" (data) } (data) 0123849 Page 3 of 16
Background image of page 3

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

View Full DocumentRight Arrow Icon
public class OrdinaryTreeNode implements TreeNode { private String key; private Object contents; public OrdinaryTreeNode(String k, Object c) { this.key = k; this.contents = c; } public String getNodeKey() { return this.key; } public boolean equalTo(TreeNode N) { return key.equals(N.getNodeKey()); / * Well , … */ "0123849" (data) } 0123849 (data) }
Background image of page 4
Image of page 5
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 / 16

L13_BinaryTree - The Binary Tree ADT As we have been doing,...

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

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