4.3 Stacks, Queues, and Linked Lists - University of Pennsylvania
4.3 Stacks, Queues, and Linked Lists
Section 4.3
1
Data Types and Data Structures
Data types: Set of values and operations on those values.
? Some are built into the Java language: int, double[], String, ... ? Most are not: Complex, Picture, Stack, Queue, ST, Graph, ...
this lecture
Data structures:
? Represent data or relationships among data. ? Some are built into Java language: arrays. ? Most are not: linked list, circular list, tree, sparse array, graph, ...
this lecture
Section 4.3
2
Collections
Fundamental data types: ? Set of operations (add, remove, test if empty) on generic data. ? Intent is clear when we insert. ? Which item do we remove?
Stack: [LIFO = last in first out] ? Remove the item most recently added. ? Ex: Pez, cafeteria trays, Web surfing.
this lecture
Queue: [FIFO = first in, first out] ? Remove the item least recently added. ? Ex: Line for help in TA office hours.
Harp
Symbol table: ? Remove the item with a given key. ? Ex: Phone book.
Section 4.3
3
Stack API
push pop
Section 4.3
4
Stack Client Example 1: Reverse
public class Reverse {
public static void main(String[] args) {
StackOfStrings stack = new StackOfStrings();
while (!StdIn.isEmpty()) {
String s = StdIn.readString();
stack.push(s);
}
while (!stack.isEmpty()) {
String s = stack.pop();
StdOut.println(s);
}
}
}
% more tiny.txt
it was the best of times
% java Reverse < tiny.txt times of best the was it
stack contents when standard input is empty
Section 4.3
5
................
................
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
- 4 3 stacks queues and linked lists university of pennsylvania
- singly linked lists cornell university
- linked list basics stanford university
- linked data structures i singly linked lists
- singly linked list class carnegie mellon university
- doubly linked lists
- lecture 09 structs and linked lists carnegie mellon university
- an introduction to linear linked list knight foundation school of
- linked lists and iterators university of bridgeport
- lecture 11 array of linked lists carnegie mellon university
Related searches
- university of pennsylvania finance depart
- university of pennsylvania finance program
- university of pennsylvania finance department
- university of pennsylvania finance master
- university of pennsylvania masters programs
- university of pennsylvania online masters
- university of pennsylvania online programs
- university of pennsylvania wharton
- university of pennsylvania mba tuition
- university of pennsylvania graduate programs
- university of pennsylvania phd programs
- university of pennsylvania transfer