Linked Lists - Colorado State University
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
- python list remove and return first element
- linked lists colorado state university
- stacks queues and deques
- built in functions university of washington
- python 3 cheat sheet limsi
- elements of programming interviews
- linked list iit kgp
- python cheat sheet
- google spreadsheet split first element
- python tutorial list and negative indexing iit guwahati
Related searches
- colorado state university calendar
- colorado state university calendar 2019 2020
- colorado state university single audit
- colorado state university cost breakdown
- colorado state university tuition fee
- colorado state university tuition 2020
- colorado state university tuition cost
- colorado state university price
- colorado state university tuition 2021
- colorado state university aar
- colorado state university career fair
- colorado state university 2019 schedule