Unformatted text preview:

CMSC 132 Object Oriented Programming II A Trick to Simplify List Implementation Department of Computer Science University of Maryland College Park 1 Typical List Implementation Class List Node head Class Node Object value Node next 2 Insert in Front of i th Element void insertInFrontOf int pos Object value if pos 0 Node newNode new Node value head head newNode else Node after head for int i 1 i pos i after after next Node newNode new Node value after next after next newNode Cool List Implementation Trick You must practice this technique if you expect to use it head is never null even for an empty list head is set to first node when list is created head is never changed the value of the first node isn t ever looked at Class List value of first Node isn t part of list final Node head new Node null Insert in Front of i th Element void insertInFrontOf int pos Object value Node after head for int i 0 i pos i after after next Node newNode new Node value after next after next newNode


View Full Document

UMD CMSC 132 - A Trick to Simplify List Implementation

Documents in this Course
Notes

Notes

8 pages

Recursion

Recursion

12 pages

Sorting

Sorting

31 pages

HTML

HTML

7 pages

Trees

Trees

19 pages

HTML

HTML

18 pages

Trees

Trees

19 pages

Honors

Honors

19 pages

Lecture 1

Lecture 1

11 pages

Quiz #3

Quiz #3

2 pages

Hashing

Hashing

21 pages

Load more
Loading Unlocking...
Login

Join to view A Trick to Simplify List Implementation and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view A Trick to Simplify List Implementation and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?