Lecture13LinkedList

Lecture13LinkedList - Linked Lists Linked Lists A linked...

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

View Full Document Right Arrow Icon
Linked Lists
Background image of page 1

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

View Full DocumentRight Arrow Icon
Linked Lists A linked list consists of a number of nodes, each of which has a reference to the next node (or null if last).
Background image of page 2
Arrays An array of objects is a list of references to objects.
Background image of page 3

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

View Full DocumentRight Arrow Icon
Linked Lists Much easier to insert Efficient to visit the elements in sequential order
Background image of page 4
But… But random access is not efficient.
Background image of page 5

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

View Full DocumentRight Arrow Icon
Java Library import java.util.*; LinkedList< type > list = new LinkedList <type> ( ); Methods: void addFirst(Object obj) void addLast(Object obj) Object getFirst(); Object getLast(); Object removeFirst( ); Object removeLast( );
Background image of page 6
Build our own! public class LinkedList { }
Background image of page 7

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

View Full DocumentRight Arrow Icon
Node Class private class Node { public String data; // data can be any type public Node next; // reference to next node public Node (String d) { data = d; next = null; } public Node (String d, Node refToNext) { data = d; next = refToNext; } } Notice anything unusual about this class?
Background image of page 8
Put it
Background image of page 9

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

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

This note was uploaded on 10/13/2008 for the course CSC 216 taught by Professor Miller during the Spring '08 term at N.C. State.

Page1 / 21

Lecture13LinkedList - Linked Lists Linked Lists A linked...

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