today s announcements
play

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


  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

  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

  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

  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 ∅ 8 ∅ 6 head head 4 / 9

  5. Example 1 insertAtFront(head, cow); pig ∅ dog cat head void insertAtFront(Node * & curr, LIT e) { } Running time? 5 / 9

  6. Example 2 3 ∅ 8 4 2 6 head void printReverse(Node * curr) { } Running time? 6 / 9

  7. Example 3 3 ∅ 8 4 2 6 5 head void printOddRev(Node * curr) { } Running time? 7 / 9

  8. Example 4 3 ∅ 8 4 2 6 5 head void reverse(Node * & curr) { } Running time? 8 / 9

  9. Remove node from list given pointer 3 ∅ 8 4 2 6 5 head void removeNode(Node * & head, Node * curr) { } Running time? 9 / 9

  10. Remove node from list given pointer 3 ∅ 8 4 2 6 5 head 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

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend