1 / 12

Linked Structures, Project 1: Linked List

Linked Structures, Project 1: Linked List. Bryce Boe 2013 / 10 /16 CS24, Fall 2013. Outline. Lab 3 Review Project 1 Notes Linked Structures. Lab 3 Review. Student Comments.

keagan
Download Presentation

Linked Structures, Project 1: Linked List

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Linked Structures, Project 1: Linked List Bryce Boe 2013/10/16 CS24, Fall 2013

  2. Outline • Lab 3 Review • Project 1 Notes • Linked Structures

  3. Lab 3 Review

  4. Student Comments • “I haven't learned anything new but instead have spent hours writing a variety of loops and random code searching for some bug…” • “What I've been doing was unceasingly putting in random functions and random parameters for the whole day trying to figure out some bugs.” • “And the worse thing is that I don't even know how it came out when I found it…”

  5. Lab 3 was supposed to be challenging • Many of you practiced fuzz testing • Great way to perform black-box testing to attempt to find bugs • An exercise in trying something and testing if it worked • Code, compile, test (repeat over and over) • Now we’ll make sense of the bugs

  6. Project 1 Notes • Do not use static or global variables (you will lose significant points if you rely on them) • You must validate all memory allocations • if an allocation fails make sure you don’t leak other memory • Get the array list working up to size N before dealing with reallocation

  7. Linked Structures

  8. What’s wrong with using arrays to store data? • Arrays require continuous chunks of memory • Unless the array is full, there is wasted space • Expanding the array is typically done by doubling the size • Worst case time: Have to copy all the existing items • Hint: realloc does this for you (recall how realloc is implemented)

  9. How long does it take? • Appending an item to a non-full array? • Appending an item to a full-array? • Removing an item from the end of the array? • Removing an item from the beginning of the array? • Accessing an element in the middle of the

  10. Single-link Node structure struct Node { int_data; struct Node *_next; }

  11. Node allocation walkthrough • Add an initial node • Add another node at the beginning • Add another node at the end • Remove a node at the beginning • Remove a node at the end

  12. How can we access the data of specific elements? • The data of the second element? • head->_next->_data • The data of the third element? • head->_next->_next->_data; • (Generally) The data of the nth element? struct Node *tmp = head; for (inti = 0; i < n; ++i) tmp = tmp->_next; tmp->_data;

More Related