Please review the code
package com.gmail.practice;
import java.util.Arrays;
public class StacksForTwo {
int size;
int[] stack;
int top1;
int top2;
public StacksForTwo(int arraysize)
{
size = arraysize;
stack = new int[size];
top1 = -1;
top2 = size;
}
public void push1(int x)
{
if(top1 < top2-1)
{
top1++;
stack[top1] = x;
}else{
System.out.println("stackoverflow");
}
}
public void push2(int y)
{
if(top1 < top2-1)
{
top2--;
stack[top2] = y;
}else{
System.out.println("stack overflow");
}
}
public void pop1()
{
if(top1 >= 0)
{
top1--;
System.out.println("The popped out number is"+" "+stack[top1+1]);
}else{
System.out.println("stack underflow");
}
}
public void pop2()
{
if(top2 < size)
{
top2++;
System.out.println("The popped out number is"+" "+stack[top2+1]);
}else{
System.out.println("stack underflow");
}
}
public void display()
{
System.out.println(Arrays.toString(stack));
}
public static void main(String[] args)
{
StacksForTwo sft = new StacksForTwo(10);
sft.push1(4);
sft.push1(5);
sft.push1(3);
sft.push1(2);
sft.push2(6);
sft.push2(4);
sft.display();
sft.push2(8);
sft.push1(2);
sft.push2(6);
sft.push2(4);
sft.push2(8);
sft.display();
}
}
package com.gmail.practice
,) Neither code nor question state the purpose of coding this. \$\endgroup\$