Lecture11-3

# Lecture11-3 - DataStructures CSCI 132 Spring 2012 Lecture...

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

1 Data Structures   CSCI 132, Spring 2012 Lecture 11 Stacks as Linked Lists

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

View Full Document
2 Linked Lists myList data 1 data 2 data 3 data 4 Head of List Tail of List Node
3 Advantages of Linked Lists A linked list takes up only as much space in memory as is needed for the length of the list. The list expands or contracts as you add or delete elements. Elements can be added to (or deleted from) either end, or added to (or deleted from)the middle of the list.

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

View Full Document
4 Implementing a node struct Node { // data members Node_entry entry; //data in node Node *next; //pointer to next node //constructors Node( ); Node( Node_entry item, Node *add_on = NULL); };
5 Node Constructors Node :: Node( ) { next = NULL; } Node :: Node( Node_entry item, Node *add_on) { entry = item; next = add_on; }

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

View Full Document
6 Creating a linked list Node myNode(3); // create a Node named myNode Node *p, *q; p = new Node(10); // p points to a new Node q = new Node(6, p); // q points to a Node that points to p Node *r; r = &myNode; //r points to myNode r ->next = q; //myNode points to q 3 6 10 r q p myNode
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 17

Lecture11-3 - DataStructures CSCI 132 Spring 2012 Lecture...

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

View Full Document
Ask a homework question - tutors are online