1. Stack: Examine the item most recently added. --> FILO
Queue: Examine the item least recently added. --> FIFO
2. Linked list implementation of Stack :
public class LinkedStack<Item>
{
private Node first = null;
private class Node
{
Item item;
Node next;
}
public boolean isEmpty()
{ return first == null; }
public void push(Item item)
{
Node oldfirst = first;
first = new Node();
first.item = item;
first.next = oldfirst;
}
public Item pop()
{
Item item = first.item;
first = first.next;
return item;
}
}
3. Array implementation of Stack :
a) Underflow : throw exception if pop from an empty stack.
b) Loitering : set the reference in array to null when the item is popped
c) Overflow : If array is full, create a new array of twice the size, and copy items. ( ~3N)
d) Shrink : halve size of array when array is one-quarter full.
4. Linked List implementation of Queue:
public class LinkedQueue<Item>
{
private Node first, last;
private class Node
{ /* same as in Stack */ }
public boolean isEmpty()
{ return first == null; }
public void enqueue(Item item)
{
Node oldlast = last;
last = new Node();
last.item = item;
last.next = null;
if (isEmpty()) first = last;
else oldlast.next = last;
}
public Item dequeue()
{
Item item = first.item;
first = first.next;
if (isEmpty()) last = null;
return item;
}
}
5. Array implementation of a queue.
a) Use array q[] to store items in queue.
b) enqueue(): add new item at q[tail].
c) dequeue(): remove item from q[head].
d) Update head and tail modulo the capacity.
e) Add resizing array.
6. Bag : Adding items to a collection and iterating (when order doesn't matter).
7. Stack Applications :
a) Parsing in a compiler.
b) Java virtual machine.
c) Undo in a word processor.
d) Back button in a Web browser.
e) PostScript language for printers.
f) Implementing function calls in a compiler.
8. How a compiler implements a function.
a) Function call: push local environment and return address.
b) Return: pop return address and local environment.
Note. We can always use an explicit stack to remove recursion.
9. Dijkstra's two-stack algorithm computes the same value if the operator occurs after the two values. And all of the parentheses are redundant! We can use postfix or "reverse Polish" notation:
1 2 3 + 4 5 * * +
- 大小: 44.7 KB
分享到:
相关推荐
数据结构--C语言描述 Chapter03-Stacks-and-Queues英文课件
本项目"cs-guided-project-queues-stacks"专注于两个基本数据结构:队列(Queues)和堆栈(Stacks),它们在Python编程中有着广泛的应用。下面我们将深入探讨这两个数据结构以及它们在实际问题中的运用。 ### 队列...
首先,“Probability, Markov chains, queues and simulation” 这个标题暗示了书中将探讨几个关键的数学和计算机科学领域,它们对于性能建模至关重要。 **概率论**: - **概率试验**:这是研究随机现象的基础,...
数据结构英文教学课件:chapter4 Stacks and Queues.ppt
Chapter 12 - Queues and Stacks Chapter 13 - Binary Trees Chapter 14 - Case Studies in Design: Abstracting Indirection Part IV - The Limits of Computer Science Chapter 15 - Exponential Growth...
A complete primer for the technical ...Chapter 4 Queues and Stacks Chapter 5 Heaps Chapter 6 Hash Tables Chapter 7 Binary Search Chapter 8 Graphical Search Chapter 9 Selection Chapter 10 Sorting
Java中的栈(Stack)和队列(Queue)是两种重要的数据结构,它们在程序设计中扮演着关键角色,尤其在处理对象的临时存储和管理数据流时。本篇内容主要探讨了栈和队列的不同实现方式,以及它们的应用场景。...
根据提供的文件信息,本书《Markov chains, Gibbs Fields Monte Carlo Simulation, and Queues》由Pierre Bremaud撰写,被广泛认为是学习随机过程的重要教材之一。以下将根据标题、描述以及部分目录信息来总结书中的...
一. 实验目的 本次实验的主要目的是理解和掌握线性数据结构——双端队列(Double-Ended Queue,简称deque)的实现与应用。通过实际编程,加深对双端队列特性的理解,如其在头部和尾部进行插入和删除操作的灵活性。...
在本章"Chapter4 Lists, Stacks, and Queues"中,我们将深入探讨三种基本的数据结构:列表、栈和队列。 首先,列表是一种有限的、有序的数据元素序列,每个元素都有其特定的数据类型。列表可以为空,其长度表示当前...
本压缩包"Data-structures---stacks-and-queues.zip"聚焦于两种重要数据结构——栈和队列,尤其关注在Linux环境下的应用。下面将详细阐述这两种数据结构的概念、特性以及在实际编程中的应用。 栈(Stack)是一种...
The Part I of book consist of c++ review and preliminaries, Part II consists of data structures including Lists, Dictionaries, Stacks, Queues and trees and their different types of representations, ...
标题和描述中提到的知识点主要涉及数据结构中的表、栈和队列,这些都是计算机科学中基本且重要的概念。下面将详细解释这些概念及其应用。 **表(List ADT)** 表是一种线性数据结构,允许在任何位置进行插入和删除...
C/C++ Reference General C/C++ Pre-processor commands Operator Precedence Escape Sequences ...C++ Stacks C++ Sets C++ Multisets C++ Maps C++ Multimaps C++ Bitsets All C++ Functions
包括: General C/C++ Pre-processor commands Operator Precedence ...C++ Stacks C++ Sets C++ Multisets C++ Maps C++ Multimaps C++ Bitsets Iterators All C++ Functions 非常好用!英文版的
C++ 语言参考 英文版 C/C++ Reference General C/C++ Pre-processor commands Operator Precedence ...C++ Stacks C++ Sets C++ Multisets C++ Maps C++ Multimaps C++ Bitsets All C++ Functions
在计算机科学领域,数据结构是基础且至关重要的概念,它为高效地组织和处理数据提供了方法。...在实际编程项目中,如“CS42-DS-A-2-M2-Queues-and-Stacks-main”所示,这些基本数据结构的运用将贯穿始终。
Linked Lists, Stacks, Queues,Trees, Priority Queue and Heaps, Disjoint Sets ADT, Graph Algorithms, Sorting, Searching, Selection Algorithms [Medians], Symbol Tables, Hashing, String Algorithms, ...
You will be able to create complex data structures such as graphs, stacks and queues. We will explore the application of binary searches and binary search trees. You will learn the common techniques ...