收藏 分享(赏)

Data Structures with C++ using STL 2E Chapter 1.ppt

上传人:j35w19 文档编号:7356059 上传时间:2019-05-15 格式:PPT 页数:42 大小:879.50KB
下载 相关 举报
Data Structures with C++ using STL 2E Chapter 1.ppt_第1页
第1页 / 共42页
Data Structures with C++ using STL 2E Chapter 1.ppt_第2页
第2页 / 共42页
Data Structures with C++ using STL 2E Chapter 1.ppt_第3页
第3页 / 共42页
Data Structures with C++ using STL 2E Chapter 1.ppt_第4页
第4页 / 共42页
Data Structures with C++ using STL 2E Chapter 1.ppt_第5页
第5页 / 共42页
点击查看更多>>
资源描述

1、1,Storage Containers -General -Vectors (3 slides) -Lists -MapsADTs (2 slides)Classes -Declaration -Private/Public Sections (3 slides)time24 function addTime(),Chapter 1 Introduction to Object Technology,Scope Resolution Operator Rectangle Class (4 slides)API -Constructor -Operations -randomNumber Cl

2、ass (2 slides)Generating Random NumbersString Functions and Operations (6 slides)Summary Slides (9 slides),2,Storage Containers ( General ),Example,3,4,Storage Containers ( Vectors),A vector has all of the nice indexing features of an array along with the ability to dynamically grow to meet demand.,

3、/ output elements of vfor (i = 0; i v.size(); i+)cout vi “ “,5,Storage Containers ( Vectors),A vector is a “super-array“, meaning all familiar array algorithms work. You also have the freedom to to grow or shrink it.,6,Storage Containers ( Vectors),Vectors allow for direct access to their elements t

4、hrough an index, but are not efficient storage structures for: insertion of items at arbitrary positions in a list. deletion of items at arbitrary positions in a list.,7,8,Storage Containers ( Lists ),list container each element has a reference that identifies the next item in the list. Adding a new

5、 item involves breaking a link in the chain and creating two new links to connect the item.,9,Storage Containers ( Maps ),maps use a tree structure to store data. A is a container that stores elements as nodes emanating from a root.,TREE,10,A search tree holding airbill numbers,The tree holds 8 elem

6、ents. Any search requires at most 3 movements along a path from the root.,BACK,11,Abstract Data Types,ADT Operation Description operationName: Action statement that specifies the input parameters, the type of operation on the elements of the data structure, and the output parameter Preconditions: Ne

7、cessary conditions that must apply to the input parameters and the current state of the object to allow successful execution of the operation. Postconditions: Changes in the data of the structure caused by the operation.,12,Abstract Data Types ( time24 Class ),duration(t): Time t is an input paramet

8、er. Measure the length of time from the current time to time t and return the result as a time24 value. Precondition: Time t must not be earlier than the current time,13,Classes ( Declaration ),14,Classes ( Private/Public Sections),The public and private sections in a class declaration allow program

9、 statements outside the class different access to the class members.,15,Classes ( Private/Public Sections),Public members of a class are the interface of the object to the program. Any statement in a program block that declares an object can access a public member of the object,16,Classes ( Private/

10、Public Sections),The private section typically contains the data values of the object and utility functions that support class implementation. Only member functions of the class may access elements in the private section.,17,Runtime execution of the time24 function addTime(),18,Scope resolution Oper

11、ator,The symbol “:“ signals the compiler that the function is a member of the class. The statements in the function body may access all of the public and private members of the class.The “:” operator allows you to code a member function like any other free function.,returnType className:functionName

12、(argument list) ,19,20,21,22,23,API ( Constructor ),24,API ( Operations ),25,API ( randomNumber Class),26,API ( randomNumber Class),27,Generating Random Numbers,The loop generates 5 integer random numbers in the range 0 to 40 and 5 real random numbers in the range 0 to 1.int item, i;double x;for (i

13、= 0; i 5; i+)item = rndA.random(40); / 0 = item 40x = rndB.frandom(); / 0.0 = x 1.0cout item “ “ x;,28,String Functions and Operations,29,String Functions and Operations,30,String Functions and Operations,31,String Functions and Operations,32,String Functions and Operations,33,String Functions and O

14、perations,34,Summary Slide 1,- A data structure is a systematic way of organizing and accessing data. - Programmer-defined data structures bundle data with operations that manipulate the data. - The structures, called containers have operations to access, insert, and remove items from the collection

15、.,35,Summary Slide 2,- Arrays have some limitations: fixed size. No automatic growth to meet the needs of an application. (Solution - Use Vector Containers) insertion and deletion inside the array requires the costly movement of data either to the right or to the left. (Solution - Use List Container

16、s) - Efficient access to an element requires knowledge of its position in the list.,36,Summary Slide 3,- Abstract Data Types (ADTs) are a model used to understand the design of a data structure. - ADTs specify the type of data stored and the operations that support the data. - Viewing a data structu

17、re as an ADT allows a programmer to focus on an idealized model of the data and its operations.,37,Summary Slide 3a,- An ADT provides simple and clear description of: the input to an operation. the action of the operation. its return type. - Preconditions: Part of the description of an operation. A

18、listing of the conditions that must apply in order for the operation to execute successfully. - Postconditions: Indicate changes to the objects data caused by the operation. Necessary because operations often alter the value of data.,38,Summary Slide 4,- The private section of a class contains the d

19、ata and operations that the public member functions use in their implementation. - The splitting of a class into public and private parts is known as information hiding. - A class encapsulates information by bundling the data items and operations within an object.,39,Summary Slide 5,- The implementa

20、tion of C+ class member functions is different from the implementation of free functions.- Each function name must include the class scope operator : that designates class membership. - The constructor is a special function with no return type. - The constructor initializes the data members of the c

21、lass by using its initialization list.,40,Summary Slide 6,- A member function can be implemented inside the class declaration by using inline code. The semicolon (;) in the function prototype is replaced by the function body. The compiler inserts the statements in the function body in place of the f

22、unction, avoiding the function call and return mechanism. - The process provides efficiency at the expense of increased code size.,41,Summary Slide 7,- Application Programming Interface: - Allows other programmers to use the public interface of the class without having to view the technical details

23、of the class declaration or implementation.,42,Summary Slide 8,- C+ provides two approaches to string handling. Older Method:C-style string - a character array that designates the end of the string by using the NULL character. - Used by the C programming language and older C+ programs.2) Modern Method: string class - provides a large public interface containing many useful operations. - Example: I/O operations.,

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 企业管理 > 管理学资料

本站链接:文库   一言   我酷   合作


客服QQ:2549714901微博号:道客多多官方知乎号:道客多多

经营许可证编号: 粤ICP备2021046453号世界地图

道客多多©版权所有2020-2025营业执照举报