Question: Use your implemented LinkedList class to implement: A queue with the methods - o enqueue(V): Put value V to the queue dequeue(): Get and remove



Use your implemented LinkedList class to implement: A queue with the methods - o enqueue(V): Put value V to the queue dequeue(): Get and remove a value from the queue A stack with the methods - push(V): Put value V to the stack o pop(): Get and remove a value from the stack top(): Get a value from the stack but does not remove it You may need to add additional methods to the Linked List class Possible Solution public class LinkedList class Node { int v; Node next; public void print() { print(head.next); System.out.println(); } public Node(int v) { this.v = v; } } private Node head = new Node(0); private Node tail = head; private int size = 0; private void print(Node n) { if (n == null) return; System.out.print(n.v + "\t"); print(n.next); } public void append(int v) { tail.next = new Node(v); tail = tail.next; size++; } public void printRev() { printRev(head.next); System.out.println(); } private void printRev(Node n) { if (n == null) return; printRev(n.next); System.out.print(n.v + "\t"); } Activate W Go to Setting public void insertAsc(int v) { Node p = head, n = new Node(v); while(p.next != null && p.next.v
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
