Question
you need to use the code below , to add this >>> Write a method that takes a stack of integers intStack and an integer
you need to use the code below , to add this >>> Write a method that takes a stack of integers intStack and an integer value num. The method returns true if num is in the stack and false otherwise. The method must also return the elements of intStack back to intStack in their original order. You may only use a queue and some primitive variables. Your method should not use another stack or an array. Test your method.
-------------------------------------------------------------------------------------------------------------------------
import java.util.*; public class testReverseQueue{ static Scanner console = new Scanner(System.in); public static void main(String[] args) { ArrayQueue myQueue = new ArrayQueue(100); int num; while(true){ System.out.print("Enter an integer value (999 to stop): "); num = console.nextInt(); if(num==999) break; myQueue.enqueue(num); } System.out.println("Content of myQueue befor reversing: "); System.out.println(myQueue.toString()); reverseQueue(myQueue); System.out.println("queue content after reversing:"); System.out.println(myQueue.toString()); } // End of main public static void reverseQueue(ArrayQueue Q){ int q_size; q_size=Q.size(); ArrayStack tempStack = new ArrayStack(q_size); for(int i=0; i
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started