Вы находитесь на странице: 1из 44

Chapter 20 – Data Structures

Outline
20.1 Introduction
20.2 Self-Referential Classes
20.3 Dynamic Memory Allocation
20.4 Linked Lists
20.5 Stacks
20.6 Queues
20.7 Trees

 2003 Prentice Hall, Inc. All rights reserved.


20.1 Introduction

• Dynamic data structures


– Grow and shrink at execution time
– Several types
• Linked lists
• Stacks
• Queues
• Binary trees

 2003 Prentice Hall, Inc. All rights reserved.


20.2 Self-Referential Classes

• Self-referential class
– Contains instance variable referring to object of same class
class Node {
private int data;
private Node nextNode; // reference to next linked node
}
• Member nextNode is a link
– nextNode “links” a Node object to another Node object

 2003 Prentice Hall, Inc. All rights reserved.


20.2 Self-Referential Classes (cont.)

15 10

Fig 20.1 Self-referential-class objects linked together.

 2003 Prentice Hall, Inc. All rights reserved.


20.3 Dynamic Memory Allocation

• Dynamic memory allocation


– Obtain more memory at execution time to store new objects
• Declaration and class-instance creation expression
Node nodeToAdd = new Node ( 10 );

 2003 Prentice Hall, Inc. All rights reserved.


20.4 Linked Lists

• Linked list
– Linear collection of self-referential classes (nodes)
– Connected by reference links
– Nodes can be inserted and deleted anywhere in linked list
– Last node is set to null to mark end of list

 2003 Prentice Hall, Inc. All rights reserved.


20.4 Linked Lists (cont.)

firstNode lastNode

H D ... Q

Fig 20.2 Linked list graphical representation.

 2003 Prentice Hall, Inc. All rights reserved.


1 // Fig. 20.3: List.java
2 // ListNode and List class declarations.
Outline
3 package com.deitel.jhtp5.ch20;
4
5 // class to represent one node in a list List.java
6 class ListNode {
7 Self-referential
Lines 6-10class
8 // package access members; List can access these directly ListNode contains data
9 Object data;
and link to nextNode
10 ListNode nextNode;
11
12 // create a ListNode that refers to object
13 ListNode( Object object )
14 {
15 this( object, null );
16 }
17
18 // create ListNode that refers to Object and to next ListNode
19 ListNode( Object object, ListNode node )
20 {
21 data = object;
22 nextNode = node;
23 }
24
25 // return reference to data in node
26 Object getObject()
27 {
28 return data; // return Object in this node
29 }
30

 2003 Prentice Hall, Inc.


All rights reserved.
31 // return reference to next node in list Outline
32 ListNode getNext()
33 {
34 return nextNode; // get next node List.java
35 }
36
37 } // end class ListNode Line 41
38 Reference to first
39 // class List declaration node in linked
Line list
42
40 public class List {
41 private ListNode firstNode; Reference
42 private ListNode lastNode;
Line 55 to last
node in linked list
43 private String name; // string like "list" used in printing
44
45 // construct empty List with "list" as the name
46 public List()
47 {
48 this( "list" );
49 }
50
51 // construct an empty List with a name
52 public List( String listName )
53 {
54 name = listName;
First and last nodes in
55 firstNode = lastNode = null;
56 }
empty list are null
57
58 // insert Object at front of List
59 public synchronized void insertAtFront( Object insertItem )
60 {

 2003 Prentice Hall, Inc.


All rights reserved.
61 if ( isEmpty() ) // firstNode and lastNode refer to same object If list is empty, the first and
Outline
62 firstNode = lastNode = new ListNode( insertItem ); last node should refer to the
63
newly inserted node
64 else // firstNode refers to new node List.java
65 firstNode = new ListNode( insertItem, firstNode );
66 }
67
If list is not empty,
Lines the first
61-62
68 // insert Object at end of List node should refer to the
69 public synchronized void insertAtBack( Object insertItem ) newly inserted node
Line 65
70 {
71 if ( isEmpty() ) // firstNode and lastNode refer to same Object
If list is empty, the first and
72 firstNode = lastNode = new ListNode( insertItem );
Lines 71-72
last node should refer to the
73
74 else // lastNode's nextNode refers to new node
newly inserted
Line 74node
75 lastNode = lastNode.nextNode = new ListNode( insertItem );
76 }
If list is not Lines
empty,81-82
the last
77
78 // remove first node from List node should refer to the
79 public synchronized Object removeFromFront() throws newly inserted node
EmptyListException
80 {
81 if ( isEmpty() ) // throw exception if List is empty
If list is empty, removing a
82 throw new EmptyListException( name );
83
node causes an exception
84 Object removedItem = firstNode.data; // retrieve data being removed
85
86 // update references firstNode and lastNode
87 if ( firstNode == lastNode )
88 firstNode = lastNode = null;
89 else
90 firstNode = firstNode.nextNode;

 2003 Prentice Hall, Inc.


All rights reserved.
91 Outline
92 return removedItem; // return removed node data
93
94 } // end method removeFromFront List.java
95
96 // remove last node from List
97 public synchronized Object removeFromBack() throws EmptyListException Line 100
98 {
99 if ( isEmpty() ) // throw exception if List is empty If list is empty, Lines 112-117
removing a
100 throw new EmptyListException( name );
node causes an exception
101
102 Object removedItem = lastNode.data; // retrieve data being removed
103
104 // update references firstNode and lastNode
105 if ( firstNode == lastNode )
106 firstNode = lastNode = null;
107
108 else { // locate new last node
109 ListNode current = firstNode;
110
111 // loop while current node does not refer to lastNode
112 while ( current.nextNode != lastNode ) If list is not empty, the second-to-
113 current = current.nextNode;
last node becomes the last node
114
115 lastNode = current; // current is new lastNode
116 current.nextNode = null;
117 }
118
119 return removedItem; // return removed node data
120
121 } // end method removeFromBack
 2003 Prentice Hall, Inc.
All rights reserved.
122 Outline
123 // determine whether list is empty
124 public synchronized boolean isEmpty()
125 { List.java
126 return firstNode == null; // return true if List is empty
127 }
128 Lines 141-144
129 // output List contents
130 public synchronized void print()
131 {
132 if ( isEmpty() ) {
133 System.out.println( "Empty " + name );
134 return;
135 }
136
Traverse list and print node values
137 System.out.print( "The " + name + " is: " );
138 ListNode current = firstNode;
139
140 // while not at end of list, output current node's data
141 while ( current != null ) {
142 System.out.print( current.data.toString() + " " );
143 current = current.nextNode;
144 }
145
146 System.out.println( "\n" );
147 }
148
149 } // end class List

 2003 Prentice Hall, Inc.


All rights reserved.
1 // Fig. 20.4: EmptyListException.java Outline
2 // Class EmptyListException declaration.
3 package com.deitel.jhtp5.ch20;
4 EmptyListExcept
5 public class EmptyListException extends RuntimeException {
6
ion.java
7 // no-argument constructor
8 public EmptyListException() Lines 5-19
9 {
Exception thrown when
10 this( "List" ); program attempts to remove
// call other EmptyListException constructor
11 } node from empty list
12
13 // constructor
14 public EmptyListException( String name )
15 {
16 super( name + " is empty" ); // call superclass constructor
17 }
18
19 } // end class EmptyListException

 2003 Prentice Hall, Inc.


All rights reserved.
1 // Fig. 20.5: ListTest.java Outline
2 // ListTest class to demonstrate List capabilities.
3 import com.deitel.jhtp5.ch20.List;
4 import com.deitel.jhtp5.ch20.EmptyListException; ListTest.java
5
6 public class ListTest {
7 Line 10
Create linked list
8 public static void main( String args[] )
9 { Lines 13-16
10 List list = new List(); // create the List container
11
12 // objects to store in list
Lines 19-26
13 Boolean bool = Boolean.TRUE;
Create values
14 Character character = new Character( '$' );
15 Integer integer = new Integer( 34567 );
(Objects) to store
16 String string = "hello"; in linked-list nodes
17
18 // insert references to objects in list
19 list.insertAtFront( bool );
20 list.print();
21 list.insertAtFront( character );
22 list.print();
23 list.insertAtBack( integer );
Insert values in linked list
24 list.print();
25 list.insertAtBack( string );
26 list.print();
27

 2003 Prentice Hall, Inc.


All rights reserved.
28 // remove objects from list; print after each removal Outline
29 try {
30 Object removedObject = list.removeFromFront();
31 System.out.println( removedObject.toString() + " removed" ); ListTest.java
32 list.print();
33
34 removedObject = list.removeFromFront(); Lines 30-44
35 System.out.println( removedObject.toString() + " removed" );
36 list.print();
37 Remove values
38 removedObject = list.removeFromBack(); from linked list
39 System.out.println( removedObject.toString() + " removed" );
40 list.print();
41
42 removedObject = list.removeFromBack();
43 System.out.println( removedObject.toString() + " removed" );
44 list.print();
45
46 } // end try block
47
48 // catch exception if remove is attempted on an empty List
49 catch ( EmptyListException emptyListException ) {
50 emptyListException.printStackTrace();
51 }
52 }
53
54 } // end class ListTest

 2003 Prentice Hall, Inc.


All rights reserved.
The list is: true Outline
The list is: $ true

The list is: $ true 34567


ListTest.java

The list is: $ true 34567 hello


Program Output
$ removed
The list is: true 34567 hello

true removed
The list is: 34567 hello

hello removed
The list is: 34567

34567 removed
Empty list

 2003 Prentice Hall, Inc.


All rights reserved.
20.4 Linked Lists (cont.)
(a) firstNode

7 11

new Listnode

12

(b) firstNode

7 11

new Listnode

12

Fig 20.6 Graphical representation of operation insertAtFront.

 2003 Prentice Hall, Inc. All rights reserved.


20.4 Linked Lists (cont.)
(a) firstNode lastNode new Listnode

12 7 11 5

(b) firstNode lastNode new Listnode

12 7 11 5

Fig 20.7 Graphical representation of operation insertAtBack.

 2003 Prentice Hall, Inc. All rights reserved.


20.4 Linked Lists (cont.)
(a) firstNode lastNode

12 7 11 5

(b) firstNode lastNode

12 7 11 5

removeItem

Fig 20.8 Graphical representation of operation removeFromFront.

 2003 Prentice Hall, Inc. All rights reserved.


20.4 Linked Lists (cont.)
(a) firstNode lastNode

12 7 11 5

(b) firstNode current lastNode

12 7 11 5

removeItem

Fig 20.9 Graphical representation of operation removeFromBack.

 2003 Prentice Hall, Inc. All rights reserved.


20.5 Stacks

• Stack
– Constrained version of a linked list
• Add and remove nodes only to and from the top of the stack
– Push method adds node to top of stack
– Pop method removes node from top of stack

 2003 Prentice Hall, Inc. All rights reserved.


1 // Fig. 20.10: StackInheritance.java Outline
2 // Derived from class List.
3 package com.deitel.jhtp5.ch20;
4 StackInheritance extends
StackInheritanc
5 public class StackInheritance extends List { List, because a stack
e.java is a
6
constrained version of a linked list
7 // construct stack
8 public StackInheritance() Line 5
9 {
10 super( "stack" );
Lines 14-17
11 }
12
13 // add object to stack Lines 20-23
Method push adds
14 public synchronized void push( Object object )
15 { node to top of stack
16 insertAtFront( object );
17 }
18
19 // remove object from stack
Method pop removes
20 public synchronized Object pop() throws EmptyListException
21 { node from top of stack
22 return removeFromFront();
23 }
24
25 } // end class StackInheritance

 2003 Prentice Hall, Inc.


All rights reserved.
1 // Fig. 20.11: StackInheritanceTest.java Outline
2 // Class StackInheritanceTest.
3 import com.deitel.jhtp5.ch20.StackInheritance;
4 import com.deitel.jhtp5.ch20.EmptyListException; StackInheritanc
5
6 public class StackInheritanceTest {
eTest.java
7 Create stack
8 public static void main( String args[] ) Line 10
9 {
10 StackInheritance stack = new StackInheritance();
Lines 13-16
11
12 // create objects to store in the stack
13 Boolean bool = Boolean.TRUE; Lines 19-26
14 Character character = new Character( '$' ); Create values (Objects)
15 Integer integer = new Integer( 34567 );
to store in stack
16 String string = "hello";
17
18 // use push method
19 stack.push( bool );
20 stack.print();
21 stack.push( character );
22 stack.print();
23 stack.push( integer );
Insert values in stack
24 stack.print();
25 stack.push( string );
26 stack.print();

 2003 Prentice Hall, Inc.


All rights reserved.
27 Outline
28 // remove items from stack
29 try {
30 Object removedObject = null; StackInheritanc
31
32 while ( true ) {
eTest.java
33 removedObject = stack.pop(); // use pop method
Remove object from stack
34 System.out.println( removedObject.toString() + " popped" ); Line 33
35 stack.print();
36 }
37 }
38
39 // catch exception if stack is empty when item popped
40 catch ( EmptyListException emptyListException ) {
41 emptyListException.printStackTrace();
42 }
43 }
44
45 } // end class StackInheritanceTest

 2003 Prentice Hall, Inc.


All rights reserved.
Outline
The stack is: true
StackInheritanc
The stack is: $ true eTest.java
The stack is: 34567 $ true
Program Output
The stack is: hello 34567 $ true

hello popped
The stack is: 34567 $ true

34567 popped
The stack is: $ true

$ popped
The stack is: true

true popped
Empty stack

com.deitel.jhtp5.ch20.EmptyListException: stack is empty


at com.deitel.jhtp5.ch20.List.removeFromFront(List.java:82)
at com.deitel.jhtp5.ch20.StackInheritance.pop(
StackInheritance.java:22)
at StackInheritanceTest.main(StackInheritanceTest.java:33)

 2003 Prentice Hall, Inc.


All rights reserved.
1 // Fig. 20.12: StackComposition.java Outline
2 // Class StackComposition declaration with composed List object.
3 package com.deitel.jhtp5.ch20;
4 StackCompositio
5 public class StackComposition {
6 private List stackList;
n.java
7
8 // construct stack Lines 15-18
9 public StackComposition()
10 {
Lines 21-24
11 stackList = new List( "stack" );
12 }
13
14 // add object to stack
15 public synchronized void push( Object object )
Method push adds
16 { node to top of stack
17 stackList.insertAtFront( object );
18 }
19
20 // remove object from stack
21 public synchronized Object pop() throws EmptyListException
Method pop removes
22 { node from top of stack
23 return stackList.removeFromFront();
24 }
25

 2003 Prentice Hall, Inc.


All rights reserved.
26 // determine if stack is empty Outline
27 public synchronized boolean isEmpty()
28 {
29 return stackList.isEmpty(); StackCompositio
30 }
31
n.java
32 // output stack contents
33 public synchronized void print()
34 {
35 stackList.print();
36 }
37
38 } // end class StackComposition

 2003 Prentice Hall, Inc.


All rights reserved.
20.6 Queues

• Queue
– Similar to a supermarket checkout line
– Nodes inserted only at tail (back)
• Method enqueue
– Nodes removed only from head (front)
• Method dequeue

 2003 Prentice Hall, Inc. All rights reserved.


1 // Fig. 20.13: Queue.java Outline
2 // Class Queue.
3 package com.deitel.jhtp5.ch20;
4 Queue.java
5 public class Queue {
6 private List queueList;
7 Lines 15-18
8 // construct queue
9 public Queue() Lines 21-24
10 {
11 queueList = new List( "queue" );
12 }
13
14 // add object to queue
15 public synchronized void enqueue( Object object )
Method enqueue adds
16 { node to top of stack
17 queueList.insertAtBack( object );
18 }
19
20 // remove object from queue Method dequeue
21 public synchronized Object dequeue() throws EmptyListException
removes node from
22 {
23 return queueList.removeFromFront(); top of stack
24 }
25

 2003 Prentice Hall, Inc.


All rights reserved.
26 // determine if queue is empty Outline
27 public synchronized boolean isEmpty()
28 {
29 return queueList.isEmpty(); Queue.java
30 }
31
32 // output queue contents
33 public synchronized void print()
34 {
35 queueList.print();
36 }
37
38 } // end class Queue

 2003 Prentice Hall, Inc.


All rights reserved.
1 // Fig. 20.14: QueueTest.java Outline
2 // Class QueueTest.
3 import com.deitel.jhtp5.ch20.Queue;
4 import com.deitel.jhtp5.ch20.EmptyListException; QueueTest.java
5
6 public class QueueTest {
7 Line 10
Create queue
8 public static void main( String args[] )
9 { Lines 13-16
10 Queue queue = new Queue();
11
12 // create objects to store in queue
Lines 19-26
13 Boolean bool = Boolean.TRUE;
14 Character character = new Character( '$' ); Create values (Objects)
15 Integer integer = new Integer( 34567 );
to store in queue
16 String string = "hello";
17
18 // use enqueue method
19 queue.enqueue( bool );
20 queue.print();
21 queue.enqueue( character );
22 queue.print();
23 queue.enqueue( integer );
Insert values in queue
24 queue.print();
25 queue.enqueue( string );
26 queue.print();

 2003 Prentice Hall, Inc.


All rights reserved.
27 Outline
28 // remove objects from queue
29 try {
30 Object removedObject = null; QueueTest.java
31
32 while ( true ) {
33 removedObject = queue.dequeue(); // use dequeue method Line 33
Remove value from queue
34 System.out.println( removedObject.toString() + " dequeued" );
35 queue.print();
36 }
37 }
38
39 // process exception if queue is empty when item removed
40 catch ( EmptyListException emptyListException ) {
41 emptyListException.printStackTrace();
42 }
43 }
44
45 } // end class QueueCompositionTest

 2003 Prentice Hall, Inc.


All rights reserved.
The queue is: true
Outline
The queue is: true $
QueueTest.java
The queue is: true $ 34567

The queue is: true $ 34567 hello

true dequeued
The queue is: $ 34567 hello

$ dequeued
The queue is: 34567 hello

34567 dequeued
The queue is: hello

hello dequeued
Empty queue
com.deitel.jhtp5.ch20.EmptyListException: queue is empty
at com.deitel.jhtp5.ch20.List.removeFromFront(List.java:88)
at com.deitel.jhtp5.ch20.Queue.dequeue(Queue.java:23)
at QueueTest.main(QueueTest.java:33)

 2003 Prentice Hall, Inc.


All rights reserved.
20.7 Trees

• Tree
– Non-linear, two-dimensional data structure
• (unlike linked lists, stacks and queues)
– Nodes contain two or more links
– Root node is the first node
– Each link refers to a child
• Left child is the first node in left subtree
• Right child is the first node in right subtree
• Children of a specific node are siblings
• Nodes with no children are leaf nodes

 2003 Prentice Hall, Inc. All rights reserved.


20.7 Trees (cont.)

• Binary search tree


– Special ordering of nodes
• Values in left subtrees are less than values in right subtrees
– Inorder traversal
• Traverse left subtree, obtain node value, traverse right subtree
– Preorder traversal
• Obtain node value, traverse left subtree, traverse right subtree
– Postorder traversal
• Traverse left subtree, traverse right subtree, obtain node value

 2003 Prentice Hall, Inc. All rights reserved.


20.7 Trees (cont.)

A D

Fig 20.15 Binary tree graphical representation.

 2003 Prentice Hall, Inc. All rights reserved.


20.7 Trees (cont.)

47

25 77

11 43 65 93

7 17 31 44 68

Fig 20.16 Binary search tree containing 12 values.

 2003 Prentice Hall, Inc. All rights reserved.


1 // Fig. 20.17: Tree.java Outline
2 // Declaration of class TreeNode and class Tree.
3 package com.deitel.jhtp5.ch20;
4 Tree.java
5 // class TreeNode declaration
6 class TreeNode {
7 Lines 9 and 11
8 // package access members
9 TreeNode leftNode; Lines 24-32
10 int data;
Left and right children
11 TreeNode rightNode;
12
13 // initialize data and make this a leaf node
14 public TreeNode( int nodeData )
15 {
16 data = nodeData;
17 leftNode = rightNode = null; // node has no children
18 }
19
20 // locate insertion point and insert new node; ignore duplicate values
21 public synchronized void insert( int insertValue )
22 {
23 // insert in left subtree If value of inserted
24 if ( insertValue < data ) { node is less than value
25 of tree node, insert
26 // insert new TreeNode
27 if ( leftNode == null )
node in left subtree
28 leftNode = new TreeNode( insertValue );
29

 2003 Prentice Hall, Inc.


All rights reserved.
30 else // continue traversing left subtree
31 leftNode.insert( insertValue ); Outline
32 }
33
34 // insert in right subtree Tree.java
35 else if ( insertValue > data ) {
36
37 // insert new TreeNode If value of Lines 35-43
inserted node
38 if ( rightNode == null ) is greater than value of
39 rightNode = new TreeNode( insertValue ); tree node, insert node in
40
right subtree
41 else // continue traversing right subtree
42 rightNode.insert( insertValue );
43 }
44
45 } // end method insert
46
47 } // end class TreeNode
48
49 // class Tree declaration
50 public class Tree {
51 private TreeNode root;
52
53 // construct an empty Tree of integers
54 public Tree()
55 {
56 root = null;
57 }
58
59 // insert a new node in the binary search tree
60 public synchronized void insertNode( int insertValue )
61 {  2003 Prentice Hall, Inc.
All rights reserved.
62 if ( root == null ) Outline
63 root = new TreeNode( insertValue ); // create the root node here
64
65 else Tree.java
66 root.insert( insertValue ); // call the insert method
67 }
68 Lines 81-93
69 // begin preorder traversal
70 public synchronized void preorderTraversal()
71 {
72 preorderHelper( root );
73 }
74
75 // recursive method to perform preorder traversal
76 private void preorderHelper( TreeNode node )
77 {
78 if ( node == null )
79 return;
80
81 System.out.print( node.data + " " ); // output node data Preorder traversal – obtain
82 preorderHelper( node.leftNode ); data, traverse left subtree,
// traverse left subtree
83 preorderHelper( node.rightNode ); // traverse right subtree
then traverse right subtree
84 }
85
86 // begin inorder traversal
87 public synchronized void inorderTraversal()
88 {
89 inorderHelper( root );
90 }
91

 2003 Prentice Hall, Inc.


All rights reserved.
92 // recursive method to perform inorder traversal Outline
93 private void inorderHelper( TreeNode node )
94 {
95 if ( node == null ) Tree.java
96 return;
97
98 inorderHelper( node.leftNode ); // traverse left subtree Lines 98-100
99 System.out.print( node.data + " " ); // output node data
100 inorderHelper( node.rightNode );
Inorder
// traverse right subtree
traversal – traverse
Lines 115-117
101 } left subtree, obtain data, then
102 traverse right subtree
103 // begin postorder traversal
104 public synchronized void postorderTraversal()
105 {
106 postorderHelper( root );
107 }
108
109 // recursive method to perform postorder traversal
110 private void postorderHelper( TreeNode node )
111 {
112 if ( node == null )
113 return;
114
115 postorderHelper( node.leftNode ); // traverse left subtree
116 postorderHelper( node.rightNode ); Postorder traversal – traverse
// traverse right subtree
117 System.out.print( node.data + " " ); // output node data left subtree, traverse right
118 } subtree, then obtain data
119
120 } // end class Tree

 2003 Prentice Hall, Inc.


All rights reserved.
1 // Fig. 20.18: TreeTest.java Outline
2 // This program tests class Tree.
3 import com.deitel.jhtp5.ch20.Tree;
4 TreeTest.java
5 public class TreeTest {
6
7 public static void main( String args[] ) Lines 15-19
8 {
9 Tree tree = new Tree(); Line 22
10 int value;
11
12 System.out.println( "Inserting the following values: " );
Line 25
13
14 // insert 10 random integers from 0-99 in tree
15 for ( int i = 1; i <= 10; i++ ) {
Insert 10 random
16 value = ( int ) ( Math.random() * 100 ); integers in tree
17 System.out.print( value + " " );
18 tree.insertNode( value );
19 }
20
21 System.out.println ( "\n\nPreorder traversal" );
Traverse binary tree via
22 tree.preorderTraversal(); // perform preorder traversal of tree
23
preorder algorithm
24 System.out.println ( "\n\nInorder traversal" );
Traverse binary tree via
25 tree.inorderTraversal(); // perform inorder traversal of tree
inorder algorithm

 2003 Prentice Hall, Inc.


All rights reserved.
26 Outline
27 System.out.println ( "\n\nPostorder traversal" );
Traverse binary tree via
28 tree.postorderTraversal(); // perform postorder traversal of tree
29 System.out.println(); postorder algorithm
TreeTest.java
30 }
31
32 } // end class TreeTest Line 28
Inserting the following values:
39 69 94 47 50 72 55 41 97 73

Preorder traversal
39 69 47 41 50 55 94 72 73 97

Inorder traversal
39 41 47 50 55 69 72 73 94 97

Postorder traversal
41 55 50 47 73 72 97 94 69 39

 2003 Prentice Hall, Inc.


All rights reserved.
20.7 Trees (cont.)

27

13 42

6 17 33 48

Fig 20.19 Binary search tree with seven values.

 2003 Prentice Hall, Inc. All rights reserved.

Вам также может понравиться