Presentation is loading. Please wait.

Presentation is loading. Please wait.

-TAs and office hours announced

Similar presentations


Presentation on theme: "-TAs and office hours announced"— Presentation transcript:

1 -TAs and office hours announced
Updates -TAs and office hours announced -DRC students: can take quizzes after class (quizzes will remain open for 1 hour after class) (Please me)

2 -When using git for homework and projects, make sure it’s PRIVATE
Updates -When using git for homework and projects, make sure it’s PRIVATE

3 Data Structures data object set or collection of instances
integer = {0, +1, -1, +2, -2, +3, -3, …} daysOfWeek = {S,M,T,W,Th,F,Sa} Any set or collection is a data object. Set = a collection of distinct objects

4 Data Object instances may or may not be related
myDataObject = {apple, chair, 2, 5.2, red, green, Jack} The instances of integer and daysOfWeek are related. In the former, all instances are whole numbers, whereas in the latter all instances name days of the week. The instances of myDataObject don’t seem to be related.

5 Data Structure Data object + Among instances of integer 369 < 370
relationships that exist among instances and elements that comprise an instance Among instances of integer 369 < 370 = 284 You can have ordering relationships –2 before –1 before 0 before 1 etc (relational operators such as <, >, =, etc). Elements could be related by operations such as add, subtract, etc.

6 Data Structure Among elements that comprise an instance 369
3 is more significant than 6 3 is immediately to the left of 6 9 is immediately to the right of 6

7 add, subtract, predecessor, multiply
Data Structure The relationships are usually specified by specifying operations on one or more instances. add, subtract, predecessor, multiply

8 Linear (or Ordered) Lists
An abstract data type (implementation varies) instances are of the form (e0, e1, e2, …, en-1) where ei denotes a list element n >= 0 is finite list size is n Set {e0, e1, e2} is the same as Set {e1, e0, e2} but Linear List (e0, e1, e2) is different from Linear List (e1, e0, e2)

9 Linear Lists L = (e0, e1, e2, e3, …, en-1) relationships
e0 is the zero’th (or front) element en-1 is the last element ei immediately precedes ei+1 A data object is a set of instances; an instance of a linear list is an ordered set of elements.

10 Linear List Examples/Instances
Students in COP3530 = (Jack, Jill, Abe, Henry, Mary, …, Judy) Exams in COP3530 = (exam1, exam2, exam3) Days of Week = (S, M, T, W, Th, F, Sa) Months = (Jan, Feb, Mar, Apr, …, Nov, Dec) Size of Students in COP3530 is 240, Exams is 3, DOW is 7, and Months is 12. Notice that Days of Week is used as an example of both a data object and of a linear list. As a data object, {S, M, T, …} and {M, W, S, …} describe the same data object with 7 allowable instances S, M, T, … As a linear list (S, M, T, …) and (M, W, S, …) are two different instances of a linear list. Linear List itself may be viewed as data object, which is simply the set of all possible linear list instances.

11 Linear List Operations—size()
determine list size L = (a,b,c,d,e) size = 5

12 Linear List Operations—get(theIndex)
get element with given index L = (a,b,c,d,e) get(0) = a get(2) = c get(4) = e get(-1) = error get(9) = error

13 Linear List Operations—indexOf(theElement)
determine the index of an element L = (a,b,d,b,a) indexOf(d) = 2 indexOf(a) = 0 indexOf(z) = -1 The index of a nonexistent element is defined to be –1. When theElement is in the list an index between 0 and size()-1 is the result. So –1 would be an invalid index and is used to represent the case when theElement is not in the list

14 Linear List Operations—remove/erase(theIndex)
Remove/delete element with given index L = (a,b,c,d,e,f,g) erase(2) removes c and L becomes (a,b,d,e,f,g) index of d,e,f, and g decrease by 1

15 Linear List Operations—remove/erase(theIndex)
Remove/delete element with given index L = (a,b,c,d,e,f,g) remove(-1) => error remove(20) => error

16 Linear List Operations—insert(theIndex, theElement)
add an element so that the new element has a specified index L = (a,b,c,d,e,f,g) insert(0,h) => L = (h,a,b,c,d,e,f,g) index of a,b,c,d,e,f, and g increase by 1

17 Linear List Operations—insert(theIndex, theElement)
L = (a,b,c,d,e,f,g) insert(2,h) => L = (a,b,h,c,d,e,f,g) index of c,d,e,f, and g increase by 1 add(10,h) => error add(-6,h) => error

18 Data Structure Specification
Language independent Abstract Data Type C++ Abstract Class

19 Linear List Abstract Data Type
AbstractDataType LinearList { instances ordered finite collections of zero or more elements operations empty(): return true iff the list is empty, false otherwise size(): return the list size (i.e., number of elements in the list) get(index): return the indexth element of the list indexO f(x): return the index of the first occurrence of x in the list, return -1 if x is not in the list erase(index): remove the indexth element, elements with higher index have their index reduced by 1 insert(theIndex, x): insert x as the indexth element, elements with theIndex >= index have their index increased by 1 output(): output the list elements from left to right }

20 Linear List As An Abstract Class
An abstract class may include constants, variables, abstract methods, and nonabstract methods.

21 Linear List As C++ Abstract Class
template<class T> class linearList { public: virtual ~linearList() {}; virtual bool empty() const = 0; virtual int size() const = 0; virtual T& get(int theIndex) const = 0; virtual int indexOf(const T& theElement)const = 0; virtual void erase(int theIndex) = 0; virtual void insert(int theIndex, const T& theElement) = 0; virtual void output(ostream& out) const = 0; };

22 Extending A C++ Class template<class T>
class arrayList : public linearList<T> { // code for all abstract methods of linearList must come here } If arrayList does not provide an implementation for all abstract methods of linearList, arrayList also is abstract and so cannot be instantiated.

23 To-do Git: C++: http://www.sbf5.com/~cduan/technical/git/
C++:


Download ppt "-TAs and office hours announced"

Similar presentations


Ads by Google