Question: IN JAVA LANGUAGE PLEASE: PLEASE IMPLEMENT A QUEUE.JAVA WITH THIS REQUIREMENTS MyQueue.java Implement a queue using the MyStack.java implementation as your data structure. In other

IN JAVA LANGUAGE PLEASE: PLEASE IMPLEMENT A QUEUE.JAVA WITH THIS REQUIREMENTS

MyQueue.java

Implement a queue using the MyStack.java implementation as your data structure. In other words, your instance variable to hold the queue items will be a MyStack class.

  • enqueue(String item): inserts item into the queue
  • dequeue(): returns and deletes the first element in the queue
  • isEmpty(): returns true or false depending on if the queue is empty
  • printQueue(): prints the items in the queue to console
  • MyQueue(String[] list): constructor which creates the queue with the items in list in the queue: So if list had {a, b, c} the queue would look like: a first, then b, then c.

MYSTACK CODE I HAVE ALREADY IS HERE:

public class MyStack { public static class Node { String data; Node next; } private Node head; public MyStack(String[] list) { head = null; for (int i = 0; i < list.length; i++) { push(list[i]); } } public void push(String item) { Node node = new Node(); node.data = item; node.next = head; head = node; } public boolean isEmpty() { return head == null; } public String peek() { return head.data; } public String pop() { String t = peek(); head = head.next; return t; } public void printStack() { String result = ""; Node temp = head; while (temp != null) { result += temp.data + " "; temp = temp.next; } System.out.println(result); } } class MyStackTest { public static void main(String[] args) { MyStack stack = new MyStack(new String[] {"a", "b", "c"}); stack.printStack(); } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!