Download presentation
Presentation is loading. Please wait.
Published byTheodora Hutchinson Modified over 9 years ago
2
ADTs and C++ Ch 2,3,4 May 12, 2015
3
Abstract Data Type (ADT) An abstract data type is: 1.A collection of data items (storage structures) 2.Basic operations that can be performed on these items (algorithms) Called abstract because the represented data and the algorithms that operate on it are independent of the implementation (data abstraction) Thinking about what can be done with the data, not how it is done
4
Example Dictionary – A set of items indexed by keys Primary operations Search(S,k) - Given a set S and a key value k, returns a pointer x to an element in S whose key is k, if it exists Insert(S,x) - Add x to the set S Delete(S,x) - Given a pointer x to an element in the set S, remove x from S.
5
Example The actual data stored in the dictionary could be organized in any way How it is stored has no bearing on the way it is used Dictionary Implementations 1.Unsorted Array 2.Sorted Array 3.Singly-Linked Unsorted List 4.Doubly-Linked Unsorted List 5.Singly-Linked Sorted List 6.Doubly-Linked Sorted List 7.Binary Search Tree 8.Balanced Binary Search Tree 9.Hash Tables
6
C++ C++ is a particularly convenient choice to express the algorithms we will encounter. C++ is an extension of the popular C language. Most of the new features incorporated into C++ facilitate the understanding and implementation of data structures.
7
C++ Among the most important features of C++ for our study of data structures are: Data abstraction: programmers can create new types to represent whatever collections of data are convenient for their applications. Object-oriented design: the programmer-defined types play a central role in the implementation of algorithms. Use of the top-down approach Facilitation of code reuse, and the construction of general purpose libraries.
8
C++ Among the most important features of C++ for our study of data structures are: Includes an extensive, efficient, and convenient standard library. Improves on several of the inconvenient and dangerous aspects of C. Maintains, to a good degree, the efficiency that is the hallmark of the C language.
9
Classes as ADTs We can use a C++ class so long as we know the specifications of each of its methods That is, statements of precisely what each method does. We do not need to know how Data are actually stored Methods are actually programmed An important programming strategy known as information hiding
10
Classes as ADTs When the time comes to implement a class, we find that more goes on behind the scenes We need to decide what variables are needed how to store the data what functions are needed to manipulate this data All these variables and functions, however, are private to the class
11
Classes as ADTs A client program does not need to know what the private members are know how they are programmed have any access to them Instead, a client program only needs the public methods that are specified and declared for the class.
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.