Generic Stack and Queue Implementations
Create a new java class called ListNode. Implement ListNode as a generic version ofIntNode.public class ListNode {}
Create a generic class called Queue, which is a linked list implementation of a queue data type. The queue must have the following methods:
public void enqueues (T value){}This method should add a new node to the back of the queue.
public T dequeue(){}This method should remove a node from the front of the queue and return its value
public T peek(){}This method should return the value of the front node without removing it from the queue
Create a new generic class called Stack, which is a linked list implementation of a stack data type. The stack must have the following methods:
public void push(T value){}This method should add a new node to the top of the stack.
public T pop(){}This method should remove a node from the top of the stack and return its integer value
public T peek(){}This method should return the integer value of the top node without removing it from the stack
Test your implementation by creating a list of integers and a list of Strings using the generic stack and Queue classes.
Sun | Mon | Tue | Wed | Thu | Fri | Sat |
---|---|---|---|---|---|---|
23 | 24 | 25 | 26 | 27 | 28 | 1 |
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 | 29 |
30 | 31 | 1 | 2 | 3 | 4 | 5 |
Get Free Quote!
377 Experts Online