Linked Lists - PowerPoint PPT Presentation

1 / 10
About This Presentation
Title:

Linked Lists

Description:

Linked List. another data structure for collections of objects. used where an array could be used. different strengths and weaknesses. D. Goforth, COSC 2006, fall ... – PowerPoint PPT presentation

Number of Views:33
Avg rating:3.0/5.0
Slides: 11
Provided by: laurentian3
Category:

less

Transcript and Presenter's Notes

Title: Linked Lists


1
Linked Lists
  • another data structure

2
Linked List
  • another data structure for collections of objects
  • used where an array could be used
  • different strengths and weaknesses

3
Nodes
  • a linked list is composed of objects called
    nodes
  • nodes contain the data
  • nodes link to eachother to make the lined list

4
Nodes example
  • a linked list of integers is made of integer
    nodes
  • each node contains one integer value
  • each node is linked to another node

5
Nodes example java class
  • public class IntNode
  • private int data
  • private IntNode link
  • ...

247
data
data
link
link
6
Linked List of IntNodes
  • each node contains an integer
  • each node links to next node, except
  • last node has null link

247
-59
119
8
data
data
data
data
link
link
link
link
7
Comparing array and linked list
  • storing 4 integers in array

4
size
247
-59
119
8
?
?
?
?
vals
4
size
head
247
-59
119
8
data
data
data
data
link
link
link
link
8
Some lists
  • empty list
  • list with one item
  • list with four items

0
size
head
1
66
size
data
head
link
4
size
247
-59
119
8
data
data
data
data
head
link
link
link
link
9
List from Nodes
  • there is no linked list class
  • lists exist as sets of nodes linked together
  • in the collection object, the reference to the
    list is really a reference to the first node

10
IntNode class IntNode.java
  • public class IntNode
  • private int data
  • private IntNode link
  • constructors
  • accessor methods for data, link
  • modifier methods for data, link
Write a Comment
User Comments (0)
About PowerShow.com