JAVA Implement A MyQueue Class Which Implements A Queue Using Two Stacks. Private Int MaxCapacity = 4;
Question:
JAVA Implement A MyQueue Class Which Implements A Queue Using Two Stacks. Private Int MaxCapacity = 4; Private Stack Stack1; Private Stack Stack2; Note: You Can Use Library Stack But You Are Not Allowed To Use Library Queue And Any Of Its Methods Your Queue Should Not Accept Null Or Empty String Or Space As An Input You Need To Implement The Following
JAVA Implement a MyQueue class which implements a queue using two stacks. private int maxCapacity = 4; private Stack stack1; private Stack stack2; Note: You can use library Stack but you are not allowed to use library Queue and any of its methods Your Queue should not accept null or empty String or space as an input You need to implement the following methods using two stacks (stack1 & stack2) and also you can add more methods as well: public int size() public void insert(String value) public String remove() private void shiftStacks() public boolean isEmpty() public boolean isFull()
public class MyQueue{ private int maxCapacity = 4; private Stack stack1; private Stack stack2; public MyQueue(){ } public int size(){ } public void insert(String value){ } public String remove(){ } private void shiftStacks(){ } public boolean isEmpty() { } public boolean isFull(){ } @Override //[QueueSize:Full/Empty:QueueElementsList] public String toString(){ shiftStacks(); StringBuilder sb = new StringBuilder(\"[\"); sb.append(this.size()).append(\":\"); if(this.isEmpty()) sb.append(\"Empty\").append(\":\"); else if (this.isFull()) sb.append(\"Full\").append(\":\"); while(!isEmpty()){ sb.append(this.remove()); if(this.size()!=0) sb.append(\", \"); } sb.append(\"]\"); return sb.toString(); } }