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

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

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.

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

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

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

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

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

View Full Document
Remove node in fixed position (given a pointer to node you wish to remove) : 3 7 4 2 8 Solution #2:
Remove node in loc th position: (would a sentinel help?) 3 7 4 2 8 Analysis: Remove kth in array:

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

View Full Document

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.

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