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

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

View Full Document Right Arrow Icon
1 Data Structures   CSCI 132, Spring 2012 Lecture 11 Stacks as Linked Lists
Background image of page 1

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

View Full DocumentRight Arrow Icon
2 Linked Lists myList data 1 data 2 data 3 data 4 Head of List Tail of List Node
Background image of page 2
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.
Background image of page 3

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

View Full DocumentRight Arrow Icon
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); };
Background image of page 4
5 Node Constructors Node :: Node( ) { next = NULL; } Node :: Node( Node_entry item, Node *add_on) { entry = item; next = add_on; }
Background image of page 5

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

View Full DocumentRight Arrow Icon
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
Background image of page 6
Image of page 7
This is the end of the preview. Sign up to access the rest of the document.

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 Right Arrow Icon
Ask a homework question - tutors are online