Dale - Computer Science Illuminated 334

Dale - Computer Science Illuminated 334 - purposes it means...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
9.7 Trees 307 Figure 9.19 A binary search tree built from strings john tree phil becca lila jim kate mari judy june sarah Figure 9.20 shows a trace of inserting nell in the tree in Figure 9.19. We use the contents of the info part of the node within parentheses to indicate the pointer to the subtree with that value as a root. Printing the Data in a Binary Search Tree When we printed the values in a list, we used the expression Get next item , and showed what this expression translated to in an array-based imple- mentation and in a linked implementation. What the expression meant logically was clear: Get the next item in the linear ordering of the list. What does the expression mean within a binary search tree? Well, for our
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: purposes it means the same thing. But rather than looking at the print problem linearly, lets look at it from the trees perspective. Call to Insert 1 st If Statement Insert(( john),nell) ( john)!=null 2 nd If Statement nell>john Action/Call "! 87C >!C0 7>O C ILC788 Insert((phil),nell) (phil)!=null nell<phil "! 87C >!C0 ,8xC ILC788 Insert((lila),nell) (lila)!=null nell>lila "! 87C >!C0 7>O C ILC788 Insert((mari),nell) (mari)!=null nell>mari "! 87C >!C0 7>O C ILC788 Insert((null),nell) null=null )C078 !8,, 6 700C 0x 7>O C ILC788 0x D67>i Figure 9.20 Trace of inserting nell into the tree in Figure 9.19...
View Full Document

This note was uploaded on 01/13/2011 for the course CSE 1550 taught by Professor Marianakant during the Fall '10 term at York University.

Ask a homework question - tutors are online