DOC PREVIEW
UMD CMSC 132 - A Trick to Simplify List Implementation

This preview shows page 1-2 out of 5 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 5 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 5 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 5 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

CMSC 132: Object-Oriented Programming IIA Trick to Simplify List ImplementationDepartment of Computer ScienceUniversity of Maryland, College Park1Typical List ImplementationClass List {Node head;}Class Node {Object value;Node next;}2Insert in Front of i’th Elementvoid 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 TrickYou must practice this technique if you expect to use ithead is never null, even for an empty listhead is set to first node when list is createdhead is never changedthe value of the first node isn’t ever looked atClass List {// value of first Node isn’t part of listfinal Node head = new Node(null);}Insert in Front of i’th Elementvoid 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 =


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
Download A Trick to Simplify List Implementation
Our administrator received your request to download this document. We will send you the file to your email shortly.
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 2 2 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?