Todays announcements: PA1 out, due Sep 27, 23:59 Lecture videos out - - PowerPoint PPT Presentation

today s announcements
SMART_READER_LITE
LIVE PREVIEW

Todays announcements: PA1 out, due Sep 27, 23:59 Lecture videos out - - PowerPoint PPT Presentation

Todays announcements: PA1 out, due Sep 27, 23:59 Lecture videos out on YouTube Todays Plan Memory model Linked lists List Abstract Data Type http://zeptobars.ru/en/read/how-to-open-microchip-asic-what-inside licensed


slide-1
SLIDE 1

Today’s announcements:

◮ PA1 out, due Sep 27, 23:59 ◮ Lecture videos out on YouTube

Today’s Plan

◮ Memory model ◮ Linked lists ◮ List Abstract Data Type http://zeptobars.ru/en/read/how-to-open-microchip-asic-what-inside licensed under Creative Commons Attribution 3.0 Unported.

1 / 9

slide-2
SLIDE 2

Pointers are memory addresses

int * p, q; // what type is q? int x; p = &x; *p = 6; cout << x; cout << p; Write a statement that outputs the value of x using the variable p:

2 / 9

slide-3
SLIDE 3

More fun with pointers

int *p, *q; p = new int; q = p; *q = 8; cout << *p; // What is output? q = new int; *q = 9; p = NULL; // Do you like this? delete q; q = NULL; // Do you like this? Memory leak: Deleting a null pointer: Dereferencing a null pointer:

3 / 9

slide-4
SLIDE 4

Using memory addresses in data structures

template <class LIT> struct Node{ LIT data; Node * next; Node(LIT d, Node *p=NULL):data(d),next(p){} }; Write code to create these memory configurations (in order):

8 ∅ head 8 ∅ head 6

4 / 9

slide-5
SLIDE 5

Example 1

insertAtFront(head, cow);

cat head dog pig ∅

void insertAtFront(Node * & curr, LIT e) { } Running time?

5 / 9

slide-6
SLIDE 6

Example 2

6 head 2 3 ∅ 4 8

void printReverse(Node * curr) { } Running time?

6 / 9

slide-7
SLIDE 7

Example 3

3 ∅ 6 2 head 4 8 5

void printOddRev(Node * curr) { } Running time?

7 / 9

slide-8
SLIDE 8

Example 4

3 ∅ 6 2 head 4 8 5

void reverse(Node * & curr) { } Running time?

8 / 9

slide-9
SLIDE 9

Remove node from list given pointer

3 ∅ 6 2 head 4 8 5

void removeNode(Node * & head, Node * curr) { } Running time?

9 / 9

slide-10
SLIDE 10

Remove node from list given pointer

3 ∅ 6 2 head 4 8 5

void removeNode(Node * & head, Node * curr) { } Running time? Constant time hack (When doesn’t this work?) curr->data = curr->next->data; curr->next = curr->next->next;

9 / 9