Linear Data Structures 2.2

Linear Data Structures 2.2 - constant-time way to update...

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

View Full Document Right Arrow Icon
Last Updated: 12-01-17 9:52 AM CSE 2011 Prof. J. Elder - 56 - Running Time Adding at the head is O(1) Removing at the head is O(1) How about tail operations?
Background image of page 1

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

View Full Document Right Arrow Icon
Last Updated: 12-01-17 9:52 AM CSE 2011 Prof. J. Elder - 57 - Inserting at the Tail 1. Allocate a new node 2. Update new element 3. Have new node point to null 4. Have old last node point to new node 5. Update tail to point to new node 6. If list initially empty, have to update head as well.
Background image of page 2
Last Updated: 12-01-17 9:52 AM CSE 2011 Prof. J. Elder - 58 - Removing at the Tail • Removing at the tail of a singly linked list is not efficient! • There is no
Background image of page 3

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

View Full Document Right Arrow Icon
Background image of page 4
Background image of page 5
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: constant-time way to update the tail to point to the previous node Last Updated: 12-01-17 9:52 AM CSE 2011 Prof. J. Elder - 59 - Doubly Linked List • Doubly-linked lists allow more flexible list management (constant time operations at both ends). • Nodes store: – element – link to the previous node – link to the next node • Special trailer and header (sentinel) nodes prev next elem trailer header nodes/positions elements node Last Updated: 12-01-17 9:52 AM CSE 2011 Prof. J. Elder - 60 - Insertion • addAfter (v, z) inserts node z after node v in the list A B X C A B C v A B C p X z v z...
View Full Document

{[ snackBarMessage ]}

Page1 / 5

Linear Data Structures 2.2 - constant-time way to update...

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

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