Skip to content
Advertisement

Tag: stack

How to write a JUnit test case for ArrayStack methods

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 create another

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), this all coordinates are allocated to a stack.below is

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 Integer as its generic type, why are we able to

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

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 from this book I studied relatively much the runtime data areas of some JVM’s, especially their stack and

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 containing

Advertisement