class Elem {
		int key;
		Elem next;
	}


class Pila{
		Elem top;
	}

class Coda{
	Elem first;
	Elem last;	
}
	
public class MainClass {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
	

	}
	


	public static Pila creaPila(){
	Pila p= new Pila();
	p.top=null;
	return p;
	}

public static boolean isEmpty(Pila p){
	return p.top==null;
	}

public static void push(Pila p,Elem e){
	if(isEmpty(p)){
		p.top=e;
		e.next=null;
	}else{
		e.next=p.top;
		p.top=e;
	}
	}

public static Elem pop(Pila p){
	if(isEmpty(p)) return null;
	Elem e=p.top;
	p.top=e.next;
	e.next=null;
	return e;
}

public static int size(Pila p){
	int ris=0;
	Elem e= p.top;
	while(e!=null){
		ris++;
		e=e.next;
	}
	return ris;
}

public static Coda creaCoda(){
	Coda c= new Coda();
	c.first=null;
	c.last=null;
	return c;
	}

public static boolean isEmpty(Coda c){
	return c.first==null;
	}

public static void enqueue(Coda c,Elem e){
	if(isEmpty(c)){
		c.first=e;
		c.last=e;
		e.next=null;
		}else {c.last.next=e;
		c.last=e;
		}
	}

public static Elem dequeue (Coda c){
	if(isEmpty(c)) return null;
	Elem e=c.first;
	c.first=e.next;
	if(c.last==e) c.last=null;
	return e;	
	}

}
