I am implementing an ArrayStack and we have to create a tester for it with JUnit and I wasn’t sure what to add to check if these two methods are working. The method addAll appends all values from the given list into the other list. Equals checks if two ArrayStacks are equal. I think I would have to crea…
Tag: stack
How to output direction of shortest path?
This is a simple maze solver program. this is the simple maze i’m working on. I implemented a solution to output cordinates of the path as follow.(cordinates aquired from a BFS algorithm) but I want to output like below(omit same direction and only output direction and last coordinate to same direction)…
Java generics input type vs returned type
I’m learning about generics and am slightly confused. I’m confused about the difference between the input type and returned type for a class using generics. We are pushing in an int value of 0 and 2. But the first print statement will print “Integer”. If the stack is declared with Inte…
Prefix To Postfix Java
I need some help with my prefix to postfix code. When ever I generate the action through GUI from the expression “* 2 + 2 – + 12 9 2” it returns 2*. It should be returning “2 2 12 9 + 2 -+*”. I keep changing the code around and I keep ending up with the same result. Please
Parameter to pass in for type Class
I am trying to make a generic Stack class as shown but am unsure of what to put in for type when instantiating since I thought of doing however I get the following error of so I thought of using but I am unsure of what to put inside of cast() since it won’t take now I am stuck. Answer
How can I check if 2 given stacks has the same values? (Not necessarily in the same order)
everybody. How can I check if 2 stacks has the same values? For example, in stack1 I have [1,3,4,5] and in stack2 I have [4,3,1,5], so the stacks has the same values and the methood needs to return true. In addition, the stacks must be (in the end) as they were given (with the original values and the same ord…
Where is the super reference in a Java instance method’s stack frame?
I read Bill Venner’s excellent Inside the Java Virtual Machine book, which, in Chapter 5 explores in detail, among other things, the composition of a JVM’s stack frame. (This chapter from the book also happens to be officially published here: https://www.artima.com/insidejvm/ed2/jvm8.html) Apart f…
Is there a way to compare stack.pop() to an array (say ‘tags’) in an if statement? [closed]
Closed. This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 9 months ago. Improve this question I have the following code and would like to have the test run consider th…
Stack in Java not being able to print in specific order
Currently I’m working on a project that is supposed to be a reverse word guessing game. This is how it should work: The use keeps guessing the word until it is fully spelled out. If the user guesses the letter correctly it is revealed if not it is still reveled as shown below ⚠️ Currently I have a stack…
java: incompatible types: T cannot be converted to java.lang.String
I am currently working on a encryption and decryption service for my application, using Google Tink. The problem is the following: I want to program it without using (nearly) duplicate code and therefore I had the idea of using generics. If parsing the Strings to a byte[] is the only option I will be doing th…