急急急急急急急 java 双栈的实现
在写数据结构中的双栈,但不知如何写,要有进栈、出栈、判断满栈和空栈,求大神帮助!!!importjava.util.ArrayList;importjava.util.S...
在写数据结构中的双栈,但不知如何写,要有进栈、出栈、判断满栈和空栈,求大神帮助!!!
import java.util.ArrayList;
import java.util.Scanner;
public class Doublestack
{
public static void main(String args[])
{
class stack
{
int count;
int []top=new int[2];
int []bot=new int[2];
public stack(int count)
{
this.count = count;
}
public void push(stack a[])
{
if(this.isFull())
{
System.out.println("栈已满");
return;
}
top[0]++;
}
public boolean isEmpty(){
return bot[0]==-1;
}
public boolean isFull(){
return top[0]+1==top[1];
}
public void push() {if(this.isFull())
{
System.out.println("栈已满");
return ;
}
top[0]++;
}
}
int []top=new int[2];
int []bot=new int[2];
stack a[]=new stack[4];
a[0]=new stack(1);
a[1]=new stack(2);
a[2]=new stack(3);
a[3]=new stack(4);
bot[0]=-1;
top[0]=1;
bot[1]=3;
top[1]=2;
System.out.println(""+a[2].push());
}
} 展开
import java.util.ArrayList;
import java.util.Scanner;
public class Doublestack
{
public static void main(String args[])
{
class stack
{
int count;
int []top=new int[2];
int []bot=new int[2];
public stack(int count)
{
this.count = count;
}
public void push(stack a[])
{
if(this.isFull())
{
System.out.println("栈已满");
return;
}
top[0]++;
}
public boolean isEmpty(){
return bot[0]==-1;
}
public boolean isFull(){
return top[0]+1==top[1];
}
public void push() {if(this.isFull())
{
System.out.println("栈已满");
return ;
}
top[0]++;
}
}
int []top=new int[2];
int []bot=new int[2];
stack a[]=new stack[4];
a[0]=new stack(1);
a[1]=new stack(2);
a[2]=new stack(3);
a[3]=new stack(4);
bot[0]=-1;
top[0]=1;
bot[1]=3;
top[1]=2;
System.out.println(""+a[2].push());
}
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询