IntStack.java
interface
IntStack {
void push(int item);
int pop();
}
FixedStack.java
class
FixedStack implements IntStack {
private int stack[];
private int tos;
FixedStack(int size)
{
stack=new int[size];
tos=-1;
}
public void push(int item)
{
if(tos==stack.length-1)
System.out.println("stack
is full");
else
stack[++tos]=item;
}
public int pop()
{
if(tos<0)
{
System.out.println("stack
underflow");
return 0;
}
else
return stack[tos--];
}
public static void main(String args[])
{
FixedStack mystack1=new
FixedStack(5);
FixedStack mystack2=new
FixedStack(8);
for(int i=0;i<6;i++)
mystack1.push(i);
for(int i=0;i<9;i++)
mystack2.push(i);
System.out.println("stack
in mystack1");
for(int i=0;i<6;i++)
System.out.println(mystack1.pop());
System.out.println("stack
in mystack2");
for(int i=0;i<9;i++)
System.out.println(mystack2.pop());
}
}
bad
ReplyDeleteuseful ya ...can u snd output pls
ReplyDeleteNice information, valuable and excellent in Job, as share good stuff with good ideas and concepts, lots of great information and inspiration, both of which I need, thanks to offer such a helpful information here.
ReplyDeletemobile phone repair in Memphis
iphone repair in Memphis
cell phone repair in Memphis
phone repair in Memphis
tablet repair in Memphis
ipad repair in Memphis
mobile phone repair Memphis
iphone repair Memphis
cell phone repair Memphis
phone repair Memphis
ReplyDeletemobile phone repair in Auburn Hills
iphone repair in Auburn Hills
cell phone repair in Auburn Hills
tablet repair in Auburn Hills
ipad repair in Auburn Hills
mobile phone repair Auburn Hills
iphone repair Auburn Hills
cell phone repair Auburn Hills
phone repair Auburn Hills
tablet repair Auburn Hills
cheap hidden cameras
ismartalarm camera
dymo label maker
Waterproof Action Camera
Coleman full size air mattress
womens cotton long johns
APPLE WATCH SERIES 3 INFORMATION
Winter Cycling Jackets For Men