Stacks and Queues Flashcards
1
Q
how do you initiate a stack?
A
Stack stackname = new Stack();
2
Q
how do you add, remove, and peek from a stack?
A
stackname. push(“Value”);
stackname. pop();
stackname. peek();
stackname. search(“Value”); //to find index of an element
3
Q
how do you initiate a queue?
A
Queue queuename = new LinkedList();
4
Q
how do you add, remove, and peek from a queue?
A
queuename. offer(“Value”);
queuename. poll();
queuename. peek();