Queue And Stack Flashcards
1
Q
What is a Queue?
A
Is a first in first out (FIFO) data structure
- First one added is the first one out
2
Q
What is a Stack?
A
Is a last in first out (LIFO) data structure
- Last one added is the first one out
3
Q
Show me how to implement a Queue
A
import java.util.LinkedList;
import java.util.Queue;
Queue<Integer> queue = new LinkedList<>();</Integer>
4
Q
Show me how to implement a Stack
A
import java.util.Stack;
Stack<Integer> stack = new Stack<>();</Integer>
5
Q
Difference between a queue and a priority queue?
A
Queue is based on first in first out, elements are added to the queue based on the insertion
Priority queue sorts them in some way
6
Q
A