30.07.2013 Views

Visual Basic.NET How to Program (PDF)

Visual Basic.NET How to Program (PDF)

Visual Basic.NET How to Program (PDF)

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.

Chapter 23 Data Structures and Collections 1137<br />

Outline<br />

23.1 Introduction<br />

23.2 Self-Referential Classes<br />

23.3 Linked Lists<br />

23.4 Stacks<br />

23.5 Queues<br />

23.6 Trees<br />

23.6.1 Binary Search Tree of Integer Values<br />

23.6.2 Binary Search Tree of IComparable Objects<br />

23.7 Collection Classes<br />

23.7.1 Class Array<br />

23.7.2 Class ArrayList<br />

23.7.3 Class Stack<br />

23.7.4 Class Hashtable<br />

Summary Terminology Self-Review Exercises Answers <strong>to</strong> Self-Review Exercises Exercises<br />

23.1 Introduction<br />

The data structures that we have studied thus far, such as single-subscripted and doublesubscripted<br />

arrays, have been of fixed sizes. This chapter introduces dynamic data structures,<br />

which can grow and shrink at execution time. Linked lists are collections of data<br />

items “lined up in a row”—users can make insertions and deletions anywhere in a linked<br />

list. Stacks are important in compilers and operating systems; insertions and deletions are<br />

made only at the stack’s <strong>to</strong>p. Queues represent waiting lines; insertions are made only at<br />

the back (also referred <strong>to</strong> as the tail) of a queue, and deletions are made only from the front<br />

(also referred <strong>to</strong> as the head) of a queue. Binary trees facilitate high-speed searching and<br />

sorting of data, efficient elimination of duplicate data items, representation of file-system<br />

hierarchies and compilation of expressions in<strong>to</strong> machine language. The various data structures<br />

we just mentioned have many other interesting applications, as well.<br />

In this chapter, we discuss each of the major types of data structures and then implement<br />

programs that create and manipulate these data structures. We use classes, inheritance<br />

and composition <strong>to</strong> create and package the data structures in ways that enhance reusability<br />

and maintainability.<br />

The chapter examples are practical programs that students will find useful in<br />

advanced courses and in industrial applications. The programs devote special attention<br />

<strong>to</strong> reference manipulation.<br />

23.2 Self-Referential Classes<br />

A self-referential class contains a reference member referring <strong>to</strong> a class object of the same<br />

class type. For example, the class definition in Fig. 23.1 defines type CNode. This type has<br />

two Private instance variables (lines 5–6)—Integer mData and CNode reference

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

Saved successfully!

Ooh no, something went wrong!