I have to create a method on stacks. For some reason when I try to execute from the main method it ALWAYS shows something like ArrayStack@6acbcfc0
even thought I take the answer from the answers sheet. What is wrong? This is my coding for the method and the main class.
Stack method:
public static void splitStack(ArrayStack<Integer> st1,ArrayStack<Integer> st2)
{
ArrayStack<Integer> st11 = new ArrayStack<Integer>();
ArrayStack<Integer> st2rev = new ArrayStack<Integer>();
while(!st1.isEmpty())
{
st11.push(st1.pop());
if(!st1.isEmpty())
st2rev.push(st1.pop());
}
while(!st11.isEmpty())
st1.push(st11.pop());
while(!st2rev.isEmpty())
st2.push(st2rev.pop());
}
main method:
public static void main(String[] args) {
ArrayStack<Integer> s1 = new ArrayStack<>();
ArrayStack<Integer> s2 = new ArrayStack<>();
s1.push(0);
s1.push(1);
s1.push(3);
s1.push(4);
s1.splitStack(s1,s2);
System.out.println(s2);
}
output:
ArrayStack@6acbcfc0
Process finished with exit code 0