Topic#7 - CS162 - Topic #7 Lecture: Dynamic Data Structures...

Info iconThis preview shows pages 1–8. Sign up to view the full content.

View Full Document Right Arrow Icon
CS162 - Topic #7 Lecture: Dynamic Data Structures Review of pointers and the new operator Introduction to Linked Lists Begin walking thru examples of linked lists Programming Assignment Discussion What needs to be done for Stage #3
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
CS162 - Pointers What advantage do pointers give us? How can we use pointers and new to allocating memory dynamically Why allocating memory dynamically vs. statically? Why is it necessary to deallocate this memory when we are done with the memory?
Background image of page 2
CS162 - Pointers and Arrays Are there any disadvantages to a dynamically allocated array? The benefit - of course - is that we get to wait until run time to determine how large our array is. The drawback - however - is that the array is still fixed size .... it is just that we can wait until run time to fix that size. And, at some point prior to using the array we must determine how large it should be.
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
CS162 - Linked Lists Our solution to this problem is to use linear linked lists instead of arrays to maintain a “list” With a linear linked list, we can grow and shrink the size of the list as new data is added or as data is removed The list is ALWAYS sized exactly appropriately for the size of the list
Background image of page 4
CS162 - Linked Lists A linear linked list starts out as empty An empty list is represented by a null pointer We commonly call this the head pointer head
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
CS162 - Linked Lists As we add the first data item, the list gets one node added to it So, head points to a node instead of being null And, a node contains the data to be stored in the list and a next pointer (to the next node. ..if there is one) head a dynamically  allocated node data next
Background image of page 6
CS162 - Linked Lists To add another data item we must first
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 8
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 25

Topic#7 - CS162 - Topic #7 Lecture: Dynamic Data Structures...

This preview shows document pages 1 - 8. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online