package test_kepler;
import java.util.ArrayList;
import java.util.Stack;
// the last stack is important ; try to implement it via queue the first queue will be very important
public class wtfStack {
static int max_stack_size = 10;
ArrayList<Stack> stacks = new ArrayList<Stack>();
public wtfStack()
{
Stack stack = new Stack();
stacks.add(stack);
}
public Stack getLast()
{
return (Stack)stacks.get(stacks.size()-1);
}
public void push(int k)
{
if(getLast().size() == max_stack_size )
{
Stack newStack = new Stack();
stacks.add(newStack);
}
getLast().push(k);
}
public Object pop()
{
if(stacks.size()!=0)
{
if(getLast().size() == 0)
{
stacks.remove(stacks.size()-1);
}
return getLast().pop();
}
else
{
return null;
}
}
//print all the element in the stacks;
void print()
{
for(int i = 0;i<stacks.size();++i)
{
Stack stack_temp = stacks.get(i);
for (Object x : stack_temp)
{
System.out.println(x);
}
}
}
public static void main(String[] args) {
// TODO Auto-generated method stub
wtfStack ws = new wtfStack();
Stack test_stack = new Stack();
for(int i = 0;i<20;++i)
{
ws.push(i);
test_stack.push(i);
}
System.out.println("for the advanced");
ws.print();
System.out.println("for the naieve");
for(Object x : test_stack)
{
System.out.println(x);
}
for(int j = 0;j<15;++j)
{
System.out.println("advan");
System.out.println(ws.pop());
System.out.println("normal");
System.out.println(test_stack.pop());
}
// ws.print();
}
}
import java.util.ArrayList;
import java.util.Stack;
// the last stack is important ; try to implement it via queue the first queue will be very important
public class wtfStack {
static int max_stack_size = 10;
ArrayList<Stack> stacks = new ArrayList<Stack>();
public wtfStack()
{
Stack stack = new Stack();
stacks.add(stack);
}
public Stack getLast()
{
return (Stack)stacks.get(stacks.size()-1);
}
public void push(int k)
{
if(getLast().size() == max_stack_size )
{
Stack newStack = new Stack();
stacks.add(newStack);
}
getLast().push(k);
}
public Object pop()
{
if(stacks.size()!=0)
{
if(getLast().size() == 0)
{
stacks.remove(stacks.size()-1);
}
return getLast().pop();
}
else
{
return null;
}
}
//print all the element in the stacks;
void print()
{
for(int i = 0;i<stacks.size();++i)
{
Stack stack_temp = stacks.get(i);
for (Object x : stack_temp)
{
System.out.println(x);
}
}
}
public static void main(String[] args) {
// TODO Auto-generated method stub
wtfStack ws = new wtfStack();
Stack test_stack = new Stack();
for(int i = 0;i<20;++i)
{
ws.push(i);
test_stack.push(i);
}
System.out.println("for the advanced");
ws.print();
System.out.println("for the naieve");
for(Object x : test_stack)
{
System.out.println(x);
}
for(int j = 0;j<15;++j)
{
System.out.println("advan");
System.out.println(ws.pop());
System.out.println("normal");
System.out.println(test_stack.pop());
}
// ws.print();
}
}