CPlusPlus plus data structures, 3rd ed nell dale

1.3K 123 0
CPlusPlus plus data structures, 3rd ed   nell dale

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

C++ Plus Data Structures, Third Edition by Nell Dale ISBN:0763704814 Jones and Bartlett Publishers © 2003 (816 pages) This book focuses on abstract data types as viewed from three different perspectives: their specification, their application, and their implementation Table of Contents C++ Plus Data Structures, Third Edition Preface Software Engineering Chapter 1 Principles Data Design and Chapter 2 Implementation ADTs Unsorted List and Chapter 3 Sorted List Chapter 4 - ADTs Stack and Queue Chapter 5 - Linked Structures Chapter 6 - Lists Plus Programming with Chapter 7 Recursion Chapter 8 - Binary Search Trees Priority Queues, Heaps, Chapter 9 Graphs, and Sets Sorting and Searching Chapter 10 Algorithms Answers to Selected Exercises Appendix A - Reserved Words Appendix B - Operator Precedence A Selection of Standard Appendix C Library Routines Appendix D - Character Sets The Standard Template Appendix E Library Glossary Index List of Figures List of Tables List of C++ Examples List of Sidebars Back Cover C++ Plus Data Structures is designed for a course in Data Structures where C++ is the programming language The book focuses on abstract data types as viewed from three different perspectives: their specification, their application, and their implementation The authors stress computer science theory and software engineering principles, including modularization, data encapsulation, information hiding, data abstraction, object-oriented decomposition, functional decomposition, the analysis of algorithms, and life-cycle software verification methods Finally, through classic Dale pedagogy students are offered a clear, easy-to-understand discussion of important theoretical constructs and their implementation in C++ C++ Plus Data Structures, Third Edition Nell Dale University of Texas, Austin JONES AND BARTLETT PUBLISHERS Sudbury , Massachusetts BOSTON TORONTO LONDON SINGAPORE World Headquarters Jones and Bartlett Publishers 40 Tall Pine Drive Sudbury, MA 01776 978-443-5000 www.jbpub.com Jones and Bartlett Publishers Canada 2406 Nikanna Road Mississauga, ON L5C 2W6 CANADA Jones and Bartlett Publishers International Barb House, Barb Mews London W6 7PA UK Copyright © 2003 by Jones and Bartlett Publishers, Inc Cover image © Douglas E Walker / Masterfile All rights reserved No part of the material protected by this copyright notice may be reproduced or utilized in any form, electronic or mechanical, including photocopying, recording, or any information storage or retrieval system, without written permission from the copyright owner Chief Executive Officer: Clayton Jones Chief Operating Officer: Don W Jones, Jr Executive V.P and Publisher: Robert Holland V.P., Design and Production: Anne Spencer V.P., Manufacturing and Inventory Control: Therese Bräuer Editor-in-Chief, College: J Michael Stranz Production Manager: Amy Rose Marketing Manager: Nathan Schultz Associate Production Editor: Karen Ferreira Editorial Assistant: Theresa DiDonato Production Assistant: Jenny Mclsaac Cover Design: Night & Day Design Composition: Northeast Compositors, Inc Text Design: Anne Spencer Printing and Binding: Courier Westford Cover Printing: Lehigh Press Library of Congress Cataloging-in-Publication Data Dale, Nell B C++ plus data structures / Nell Dale.-3rd ed p cm ISBN 0-7637-0481-4 C++ (Computer program language) 2 Data structures (Computer science) I Title QA76.73.C153 D334 2003 005.7'3-dc21 2002034168 This book was typeset in Quark 4.1 on a Macintosh G4 The font families used were Rotis Sans Serif, Rotis Serif, and Prestige Elite The first printing was printed on 45# Highland Book Printed in the United States of America 06 05 04 03 02 10 9 8 7 6 5 4 3 2 1 To Al, my husband and best friend, to our children and our children's children, and to our dogs Maggie and Chrissie, who round out our family N.D Preface Historically, a course on data structures has been a mainstay of most computer science departments Over the last 18 years, however, the focus of this course has broadened considerably The topic of data structures has now been subsumed under the broader topic of abstract data types (ADTs)-the study of classes of objects whose logical behavior is defined by a set of values and a set of operations The term abstract data type describes a comprehensive collection of data values and operations; the term data structures refers to the study of data and how to represent data objects within a program; that is, the implementation of structured relationships The shift in emphasis is representative of the move towards more abstraction in computer science education We now are interested in the study of the abstract properties of classes of data objects in addition to how the objects might be represented in a program Johannes J Martin put it succinctly: " depending on the point of view, a data object is characterized by its type (for the user) or by its structure (for the implementor)."[1] Three Levels of Abstraction The focus of this book is on abstract data types as viewed from three different perspectives: their specification, their application, and their implementation The specification perspective describes the logical or abstract level of data types, and is concerned with what the operations The application level, sometimes called the user level, is concerned with how the data type might be used to solve a problem, and is focused on why the operations do what they do The implementation level is where the operations are actually coded This level is concerned with the how questions Within this focus, we stress computer science theory and software engineering principles, including modularization, data encapsulation, information hiding, data abstraction, object-oriented decomposition, functional decomposition, the analysis of algorithms, and life-cycle software verification methods We feel strongly that these principles should be introduced to computer science students early in their education so that they learn to practice good software techniques from the beginning An understanding of theoretical concepts helps students put the new ideas they encounter into place, and practical advice allows them to apply what they have learned To teach these concepts to students who may not have completed many college-level mathematics courses, we consistently use intuitive explanations, even for topics that have a basis in mathematics, like the analysis of algorithms In all cases, our highest goal has been to make our explanations as readable and as easily understandable as possible [1]Johannes J Martin, Data Types and Data Structures, Prentice-Hall International Series in Computer Science, C A R Hoare, Series Editor, Prentice-Hall International, (UK), LTD, 1986, p Prerequisite Assumptions In this book, we assume that students are familiar with the following C++ constructs: Built-in simple data types Stream I/O as provided in Stream I/O as provided in Control structures while, do-while, for, if, and switch User-defined functions with value and reference parameters Built-in array types Class construct We have included sidebars within the text to refresh students' memory concerning some of the details of these topics Changes in the Third Edition The third edition incorporates the following changes: Object-oriented constructs moved forward: In the last five years, objectoriented programming has become part of the first-year curriculum, as demonstrated by its inclusion in all variations of the first year outlined in the Computing Curricula 2001 developed by the Joint Task Force of the IEEE Computer Society and the Association for Computing Machinery Accordingly, the class concept has moved into the first semester Because of this, we assume that students have had experience using classes, and we therefore moved much of the discussion of how to define and access classes to a sidebar We have kept a small discussion in the main text Many students have already seen inheritance and polymorphism, but the concepts are too important to move to a sidebar, so we have moved them from Chapter 6 to Chapter 2 More emphasis on object-oriented design: Object-oriented design is a hard topic for most students, because people usually think procedurally in their lives Because of this, we introduce a methodology with four phases: brainstorming, during which the possible objects in a problem are isolated; filtering, during which the set of possible objects are reexamined to look for duplicates and/or missing objects; scenarios, during which hand simulations of the processing take place asking "what if" questions and assigning responsibilities to classes; and responsibility algorithms, during which the algorithms for the classes are designed We use CRC cards to capture the results of the four-phase process The output from the scenarios phase is a CRC card for each class The CRC card lists the responsibilities of the class and any other classes with which the class must collaborate, hence the name CRC: class, responsibility, collaboration More practical emphasis on testing: The concept of a multipurpose test driver is introduced in Chapter 1 After a test plan has been designed, it is implemented as input to the test driver Throughout the rest of the book, this technique is used to test the ADTs The drivers, the input data, and the output data are available on the book's web site: Chapter 5: Linked Structures Push Pop Enqueue Dequeue RetrieveItem RetrieveItem InsertItem InsertItem(item) ItemType Top Replaceltem(ItemType oldltem, ItemType newItem) Boolean Identical(StackType stack1) ItemType Front ReplaceItem(ItemType oldItem, ItemType newItem) Int Length MergeLists(SortedType& list, SortedType& result) SplitLists(ListType& list1, ListType& list2, ItemType Item) Chapter 6: Lists Plus FindItem InsertItem DeleteItem CopyStack(StackType oldStack, StackType& copy) Copy Constructor GoToTop(LineType* linePtr) GoToBottom(LineType* linePtr) InsertLine(LinePtrType linePtr, LineType newLine) Chapter 7: Programming with Recursion bool ValueInList (list, value, startIndex) Function ValueInList Function Combinations RevPrint Function RevPrint BinarySearch bool BinarySearch Function Insert Function Delete RevPrint (iterative) Function QuickSort Chapter 8: Binary Search Trees CountNodes Version 1 CountNodes Version 2 CountNodes Version 3 CountNodes Version 4 Function CountNodes Function Retrieve Function Insert Delete DeleteNode Function Delete Function Print Inorder(tree) Postorder(tree) Preorder(tree) FindNode(TreeNode* tree, ItemType item, TreeNode*& nodePtr, TreeNode*& parentPtr) FindNode InsertItem AttachNewNode AttachNewNode(revised) Chapter 9: Priority Queues, Heaps, Graphs, and Sets Priority Queue ADT Specification ReheapDown (root, bottom) ReheapUp (root, bottom) ReheapDown(heap, root, bottom) ReheapUp(heap, root, bottom) Dequeue Enqueue Graph ADT Specification DepthFirstSearch Additions to Graph ADT Shortest Path AddEdge Set ADT Specification Store(Item Type item) Delete(ItemType item) int Cardinality() SetType Union(SetType setB) SetType Intersection(SetType setB) SetType Difference(SetType setB) SetType Intersection(SetType setB) SetType Intersection(SetType setB) Chapter 10: Sorting and Searching Algorithms SelectionSort int MinIndex(values, startlndex, endIndex) BubbleSort BubbleUp(values, startlndex, endlndex) InsertionSort InsertItem(values, startIndex, endIndex) MergeSort MergeSort-Recursive Function MergeSort(values, first, last) Merge(ItemType values[ ], int leftFirst, int leftLast, int rightFirst, int rightLast) Merge (uses a local array, tempArray) BuildHeap Sort Nodes FindItem(item, location) LinearSearch (unsorted data) Delete RadixSort(values, numValues) Collect Queues Answers to Selected Exercises Checkout (Basket, Bill) CheckOut SquareMatrix ADT Specification Boolean IsThere(ItemType item) Boolean IsThere(ItemType item, UnsortedType list) DeleteItem (ItemType item) DeleteItem (ItemType item) Stack ADT Specification Queue ADT Specification Push Pop Enqueue Dequeue DepthFirstSearch IsEmpty MakeEmpty Appendix D: Character Sets The following charts show the ordering of characters in two widely used character sets: ASCII (American Standard Code for Information Interchange) and EBCDIC (Extended Binary Coded Decimal Interchange Code) The internal representation for each character is shown in decimal For example, the letter A is represented internally as the integer 65 in ASCII and as 193 in EBCDIC The space (blank) character is denoted by a "□" Left Digit(s) Right Digit 0 ( ASCII NUL SOH STX ETX EOT ENQ ACK BEL BS HT LF VT FF CR SO SI DLE DC1 DC2 DC3 DC4 NAK SYN ETB CAN EM SUB ESC FS GS □ ! " # $ % & ' ) * + , - / : ; < = > ? @ A B C D E F G H I J K L M N O P Q R S T U V W X Y Z [ \ ] ^ _ ' a b c 10 d e f g h i j k l m 11 n o p q r S t u v w 12 x y z { | } ~ DEL RS US Codes 00-31 and 127 are the following nonprintable control characters: NUL Null character SOH Start of header STX Start of text ETX End of text EOT End of transmission ENQ Enquiry ACK Acknowledge BEL Bell character (beep) BS Back space HT Horizontal tab LF Line feed VT Vertical tab FF Form feed CR Carriage return SO Shift out SI Shift in DLE Data link escape DC1 Device control one DC2 Device control two DC3 Device control three DC4 Device control four NAK Negative acknowledge SYN Synchronous idle ETB End of transmitted block CAN Cancel EM End of medium SUB Substitute ESC Escape FS File separator GS Group separator RS Record separator US Unit separator DEL Delete EBCDIC Left Digit(s) Right Digit ¢ < ( + | & ! $ * ) ; ⌝ - / 10 ^ , %_ 11 > ? 12 ` : #@ ` = " a 13 b c d e f g h i 14 j k l mn 15 o p q r 16 ~ s t u vwx y z 17 \ { } 18 [ ] 19 A B CDE F G 20 H I J 21 K LMN O PQR 22 STUV 23 WX Y Z 24 In the EBCDIC table, nonprintable control characters—codes 00–63, 250–255, and those for which empty spaces appear in the chart-are not shown C.7 The Header File cstdlib abs (i) Argument: An int expression i Function An int value that is the absolute value of i return value: atof (str) A C string (null-terminated char array) str Argument: representing a floating point number, possibly preceded by whitespace characters and a '+' or '-' Function A double value that is the floating-point equivalent return of the characters in str value: Note: Conversion stops at the first character in str that is inappropriate for a floating-point number If no appropriate characters were found, the return value is system dependent atoi(str) A C string (null-terminated char array) str Argument: representing an integer number, possibly preceded by whitespace characters and a '+' or '-' Function An int value that is the integer equivalent of the return characters in str value: Note: atol(str) Conversion stops at the first character in str that is inappropriate for an integer number If no appropriate characters were found, the return value is system dependent A C string (null-terminated char array) str Argument: representing a long integer, possibly preceded by whitespace characters and a '+' or '-' Function A long value that is the long integer equivalent of return the characters in str value: Note: Conversion stops at the first character in str that is inappropriate for a long integer number If no appropriate characters were found, the return value is system dependent exit(exitStatus) Argument: An int expression exitStatus Effect: Program execution terminates immediately with all files properly closed Function return None (a void function) value: Note: By convention, exitStatus is 0 to indicate normal program completion and is nonzero to indicate an abnormal termination labs(i) Argument: A long expression i Function A long value that is the absolute value of i return value: rand() Argument: None Function A random int value in the range 0 through RAND_MAX, a constant defined in cstdlib return value: (RAND_MAX is usually the same as INT_MAX) Note: See srand below srand(seed) Argument: An int expression seed, where seed ≥ 0 Effect: Using seed, the random number generator is initialized in preparation for subsequent calls to the rand function Function return None (a void function) value: Note: If srand is not called before the first call to rand, a seed value of 1 is assumed system(str) A C string (null-terminated char array) str representing an operating system command, exactly Argument: as it would be typed by a user on the operating system command line Effect: The operating system command represented by str is executed Function An int value that is system dependent return value: Note: Programmers often ignore the function return value, using the syntax of a void function call rather than a value-returning function call ... Library of Congress Cataloging-in-Publication Data Dale, Nell B C++ plus data structures / Nell Dale. -3rd ed p cm ISBN 0-7637-0481-4 C++ (Computer program language) 2 Data structures (Computer science) I... through classic Dale pedagogy students are offered a clear, easy-to-understand discussion of important theoretical constructs and their implementation in C++ C++ Plus Data Structures, Third Edition Nell Dale University of Texas,... The drivers, the input data, and the output data are available on the book's web site: http://computerscience.jbpub.com/cppDataStructures Reduced use of templates: The concept of generic data types, as implemented in C++ using templates, is very important

Ngày đăng: 19/04/2019, 15:41

Mục lục

  • Table of Contents

  • BackCover

  • C++ Plus Data Structures, Third Edition

  • Preface

    • Prerequisite Assumptions

    • Changes in the Third Edition

    • Content and Organization

    • Additional Features

    • Acknowledgments

    • Chapter 1: Software Engineering Principles

      • 1.1 The Software Process

      • 1.2 Program Design

      • 1.3 Verification of Software Correctness

      • Case Study

      • Summary

      • Exercises

      • Chapter 2: Data Design and Implementation

        • 2.1 Different Views of Data

        • 2.2 Abstraction and Built-In Types

        • 2.3 Higher-Level Abstraction and the C++ Class Type

        • 2.4 Object-Oriented Programming

        • 2.5 Constructs for Program Verification

        • Case Study

Tài liệu cùng người dùng

Tài liệu liên quan