Topic#7

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

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

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

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

View Full Document
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?
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.

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

View Full Document
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
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

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

View Full Document
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
CS162 - Linked Lists To add another data item we must first

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

## This note was uploaded on 03/17/2010 for the course CS 162 taught by Professor Fant during the Spring '08 term at Portland State.

### 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
Ask a homework question - tutors are online