CS163_Week1_topic2 - CS163: Data structures Week 1 topic 2:...

Info iconThis preview shows pages 1–12. Sign up to view the full content.

View Full Document Right Arrow Icon
    CS163: Data structures Week 1 – topic 2: data abstraction 5/2008
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
dbtien – Introduction to CS Data Abstraction Given what we talked about last time, we need to step through an example of an abstract data type using classes, constructors, member functions, data hiding, distinguishing the difference between what the client can do and what the ADT can do
Background image of page 2
dbtien – Introduction to CS List Abstraction Let’s begin by building a “list” abstraction Remember, the data structure used should be able to “plug and play” (i.e., be replaced without affecting the client program) Operations will include to: insert, remove, retrieve, and display create, destroy
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
dbtien – Introduction to CS List Abstraction Once the operations are understood, we can begin to examine the data Let’s build a list to be used for a student roster so, the data will include the student name, current grade % in the class, and psu id# we can use a struct or a class to represent the underlying data we will examine both of these approaches today
Background image of page 4
dbtien – Introduction to CS List Abstraction The list of students can be implemented using a variety of data structures Our choices are: array (statically allocated), array (dynamically allocated), linear linked list circular linked list doubly linked list
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
dbtien – Introduction to CS List Abstraction struct data { char * name; char * psu_id; float grade; }; Options for placement: before the class in the header file in the implementation file nested within the class
Background image of page 6
dbtien – Introduction to CS Placed in the .h file struct data { char * name; char * psu_id; float grade; }; class list { public: ...
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
dbtien – Introduction to CS Placed in the .cpp file //.h file struct data; class list { public: ... //.cpp file struct data { char * name; char * psu_id; float grade; };
Background image of page 8
dbtien – Introduction to CS Nested. .. class list { public: ... private: struct data { char * name; char * psu_id; float grade; }; };
Background image of page 9

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
dbtien – Introduction to CS Structs vs. Classes class data { char * name; char * psu_id; float grade; friend class list; }; If a class had been used, the members would have been private by default requiring the list class to be declared as a friend. ..
Background image of page 10
dbtien – Introduction to CS Structs vs. Classes My personal preference is to use structures for the underlying data this has the benefit of grouping various data types together the data is accessible directly by the class that
Background image of page 11

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 12
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 33

CS163_Week1_topic2 - CS163: Data structures Week 1 topic 2:...

This preview shows document pages 1 - 12. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online