Presentation is loading. Please wait.

Presentation is loading. Please wait.

CSE 250: Data Structures Week 3 January 28 – February 1, 2008.

Similar presentations


Presentation on theme: "CSE 250: Data Structures Week 3 January 28 – February 1, 2008."— Presentation transcript:

1 CSE 250: Data Structures Week 3 January 28 – February 1, 2008

2 Monday - Announcements Homework 1 due Friday Project 1 due 2/15

3 Monday – Game Plan Finish review of linear structures Go over implementation of linear structures and C++ details

4 Monday Queue  LIFO  Typically built upon another structure  enqueue, dequeue, peek only methods user needs

5 Monday C++ stuff Class definitions end in a ; No public modifier for class header needed private/public sections of the class are headers, each thing is not individually marked

6 Monday Typically, classes are declared in.h files and then implemented in.cpp files You can not define functions in.cpp files that have not been declared in.h However, you can not define functions in.cpp files that have been declared in.h

7 Monday #ifndef #define #endif Should be in all.h files to avoid the problem of #including the same definition twice (could happen in larger projects) Name after #ifndef should be unique

8 Monday explicit – does not allow for type conversions when calling constructor Constructors Constructor takes an initial size, but if none passed in, the initial size is set by default to 0 (in this code)  C++ constructors can not call each other

9 Monday Notice the weird : after the parameter list in the constructor, this is an initializer list It is sort of a shortcut for initialization of the private data of the class Should be used especially if the private data is not of primitive type

10 Monday Parameter Passing  Java uses call-by-value: a copy of the value of the parameter is passed into the method C++ can use call-by-value as well, but it also provides support for call-by-reference  Call-by-reference allows the function to modify the actual values of the parameters passed in Use & in front of parameter name in parameter list

11 Monday Call-by-Constant Reference  Putting const in front of a reference parameter makes a promise that the function will not change the parameter that is passed in.

12 Wednesday - Announcements Homework 1 due Friday Project 1 due 2/15

13 Wednesday – Game Plan More C++ implementation issues with class vector  Why is it all in the.h? and better explanations about stuff from last class  Copy constructor  Destructor  operator= Brief look at lists as well

14 Wednesday Const in the function definition, after params before body makes the function an accessor. Return by reference: & before the return is a return by reference.  Return by value is the default, a copy of the value is returned, return by reference returns the reference instead.

15 Wednesday Exceptions exist in C++, notice the throw in the code. Same purpose as Java. Will get into them more later if needed. operator= can be redefined to create a deep copy (an actual duplicate) of the object. Useful operator overloading for a copy constructor, or just to be able to create a duplicate.

16 Wednesday Destructor – in C++, you must give back the memory you allocate, destructors help us do that. Keyword delete to give the space back. enum lets us define constants, or can be used to define a unique type.

17 Wednesday List class  Structs – An aggregate, record type. A way to carry around a bunch of data. No functions defined on a struct. You can access the data and change the data stored only. This list implementation shows inheritance, more on that Friday.

18 Friday Announcements Homework 1 due today! Project 1 due 2/15

19 Friday – Game Plan List code

20 Friday friend – allows another object access to the function or data. Inheritance in C++ Multiple inheritance allowed Inherits public functions and data


Download ppt "CSE 250: Data Structures Week 3 January 28 – February 1, 2008."

Similar presentations


Ads by Google