Code issue , , , , , , , , , , , , , , , ,

can you check this code?


import java.util.Scanner;
import java.util.*;

class CQStack
{
public int maxSize;
public int[] stackArray;
public int top;

public CQStack(int s)
{
maxSize = s;
stackArray = new int[maxSize];
top = -1;
}
public boolean isEmpty()
{
return (top == -1);
}
public boolean isFull()
{
return (top == maxSize-1);
}
public void push(int j)
{
if(isFull())
{
return ;
}
else
{
stackArray[++top]=j;
}
}

public void pop()
{
int temp;
if(top==maxSize-1)
{
System.out.print("-1 β€œ);
}
else
{
while(top>0)
{
top–;
}
while(top<maxSize-2)
{
int c=stackArray[top];
int d=stackArray[top+1];
if(c<d)
{
System.out.print(d+” β€œ);
}
if(c>d)
{
System.out.print(”-1"+" ");
}
top++;
}
}
}
}
class Main
{
public static void main(String[] args)
{
CQStack theStack = new CQStack(100);
Scanner s=new Scanner(System.in);
int t, n,q2;
n= s.nextInt();
while(n>0)
{
q2 = s.nextInt();
theStack.push(q2);
n–;
}
theStack.pop();
}
}

in this code 1 test case not passed

It is because you are not considering the array as circular

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.