Linked Lists - CSU
Linked Lists
Walls and Mirrors Chapter 5
Linked Lists
public class Node {
private Object item;
private Node next;
public Node(int item) {...}
public Node(int item, Node next) {...}
// getters and setters
}
A linked list is a collection of Nodes:
item next
42
item next
-3
item next
17
item next
9
null
The list interface
Method
object get(index)
Returns the element at the given position
index indexOf(object)
Returns the index of the first occurrence of
the specified element
add (object)
Appends an element to the list
add (index, object)
inserts given value at given index, shifting
subsequent values right
object remove(index)
Removes the element at the specified
position (and returns it)
object remove(object)
Removes the element that corresponds to
the given object (and returns it)
int size()
returns the size of the list
boolean isEmpty()
indicates if the list is empty
clear()
removes all elements from the list
index is an int, and object is of type Object
Linked List version 1
public class LinkedList {
private Node head;
private int size;
public LinkedList() {
head = null;
size = 0;
}
methods go here
}
LinkedList
front =
size
= 0
Implementing add
?
How do we add to a linked list?
?
?
add at the end of the list
add at a given index
item next
42
item next
-3
item next
17
item next
9
null
................
................
In order to avoid copyright disputes, this page is only a partial summary.
To fulfill the demand for quickly locating and searching documents.
It is intelligent file search solution for home and business.
Related download
- chapter 2 lists arrays and dictionaries
- python 3 tutorial rxjs ggplot2 python data persistence
- ppyytthhoonn lliissttss tutorialspoint
- python lists university of michigan
- big o arraylist
- linked lists csu
- s python cheat sheet data science free
- 0 5 lab introduction to python—sets lists dictionaries
- linked lists in python kennesaw state university
- pandas dataframe notes university of idaho
Related searches
- csu online courses spring 2019
- best csu for business
- csu spring semester 2019
- csu semester or quarter
- 2019 csu rams football schedule
- csu spring schedule
- best csu for teaching credentials
- csu fullerton teacher credential program
- csu teaching credential programs
- csu second bachelor
- linked lists in java
- csu fall schedule