13-linked-lists

13-linked-lists - Route 66, Amarillo, TX CSE 114 –...

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

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon

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

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

Unformatted text preview: Route 66, Amarillo, TX CSE 114 – Computer Science I Linked Lists Linked Lists • A Linked list is a data structure (like arrays and Vector s), used to store data • Consist of objects known as nodes. • Each node has 2 components – a piece of data – a link to another node • Each node is an object of a class that has two instance variables: – one for the data – one for the link “Boston” “Phoenix” head “Denver” null Data in a node A link in a node null link signifying the end of the list head of the list points to the first node A node in the list Example: node class for a linked list of String s public class ListNode { p r i v a t e S t r i n g d a t a ; p r i v a t e L i s t N o d e n e x t ; p u b l i c L i s t N o d e ( String initData , ListNode initNext ) { data = initData; next = initNext; } } • Two parameters for the constructor: – data value for the new node – next value for the new node • If a node is the only element in the list, its next value should be null “Boston" Example: node class for a linked list of String s public class ListNode { p r i v a t e S t r i n g d a t a ; p r i v a t e L i s t N o d e n e x t ; p u b l i c L i s t N o d e ( String initData , ListNode initNext ) { data = initData; next = initNext; } } • Two parameters for the constructor: – data value for the new node – next value for the new node • If a node is the only element in the list, its next value should be null “Boston" Don’t forget accessor/mutator methods...
View Full Document

This document was uploaded on 10/22/2011.

Page1 / 14

13-linked-lists - Route 66, Amarillo, TX CSE 114 –...

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

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