lec0218-lists - Insert/Remove at front: Insert at given...

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

View Full Document Right Arrow Icon
Today’s announcements: MP3 available, EC due 2/18, due 2/25, 11:59p. Exam 1: 2/22, 7-9p, rooms TBA on Exams page of web site Today: singly linked lists – 2 tricks.
Background image of page 1

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

View Full DocumentRight Arrow Icon
Find kth position (we’ll need this later): Analysis: Find kth in array: 3 7 4 2 8 listNode * findKth(listNode * curr, int k) { }
Background image of page 2
Insert new node in kth position: Analysis: insert new kth in array: 3 6 4 }
Background image of page 3

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

View Full DocumentRight Arrow Icon
Insert new node in kth position with sentinel: X 3 6 4 Wow, this is convenient! How do we make it happen? }
Background image of page 4
Remove node in fixed position (given a pointer to node you wish to remove) : 3 7 4 2 8 Solution #1:
Background image of page 5

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

View Full DocumentRight Arrow Icon
Remove node in fixed position (given a pointer to node you wish to remove) : 3 7 4 2 8 Solution #2:
Background image of page 6
Remove node in loc th position: (would a sentinel help?) 3 7 4 2 8 Analysis: Remove kth in array:
Background image of page 7

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

View Full DocumentRight Arrow Icon
Summary (singly linked list performance):
Background image of page 8
Background image of page 9

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

View Full DocumentRight Arrow Icon
Background image of page 10
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Insert/Remove at front: Insert at given location: Remove at given location: Insert at arbitrary location: Remove at arbitrary location: Many many different variations on linked lists: In lab and MP3 youll use a doubly linked list Circularly linked list Ladder list Any kind of crazy linked structure you can imagine. To practice your skills: www.digitaltutor.net Another technique for linking memory: Doubly linked lists head tail struct listNode { LIT element; Node * prev; Node * next; //constructor(s) } void insert(listNode * curr, int k, LIT e) { listNode * p = Find(_____, curr); listNode * t = new listNode(e); } Removing k th node of a doubly linked list: head tail struct listNode { LIT element; Node * prev; Node * next; } void remove(listNode * curr, int k, LIT e) { listNode * p = Find(_____, curr); }...
View Full Document

This note was uploaded on 01/26/2012 for the course CS CS 225 taught by Professor Heeren during the Spring '09 term at University of Illinois, Urbana Champaign.

Page1 / 10

lec0218-lists - Insert/Remove at front: Insert at given...

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

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