19-generic_BST - 1 CSE 143 Lecture 19 Generic BSTs,...

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

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 1 CSE 143 Lecture 19 Generic BSTs, Comparable interface 2 A Tree of Strings Our tree is a tree of integers. What if I wanted to make a tree of Strings? public class StringTreeNode { public String data; // data stored in this node public StringTreeNode left; // reference to left subtree public StringTreeNode right; // reference to right subtree // post: constructs a StringTreeNode as a leaf with given data public StringTreeNode( String data) { this(data, null, null); } // post: constructs a StringTreeNode with the given data and links public StringTreeNode( String data, StringTreeNode left, StringTreeNode right) { this.data = data; this.left = left; this.right = right; } } What if I wanted to make a tree of People objects? BankAccount objects? Time objects? 2 3 SearchTreeNode (version 1) public class SearchTreeNode <E> { public E data; // data stored in this node public SearchTreeNode <E> left; // reference to left subtree public SearchTreeNode <E> right; // reference to right subtree // post: constructs a SearchTreeNode as a leaf with given data public SearchTreeNode( E data) { this(data, null, null);...
View Full Document

Page1 / 5

19-generic_BST - 1 CSE 143 Lecture 19 Generic BSTs,...

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

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