import java.io.*;

public class IntegerSCL {
	private Nodo nodoinit;
    public IntegerSCL () {
		nodoinit = null;
	}
	public IntegerSCL (Nodo n) {
		nodoinit = n;
	}
    public boolean empty () {
		return (nodoinit==null);
	}
	public void addElement (Integer o) throws SCLeccezione {
		Nodo aux = new Nodo();
		aux.setInfo(o);
		aux.setNext(this.nodoinit);
		nodoinit=aux;
	}
	public Integer getFirstElement () throws SCLeccezione {
		if (this.empty())
			throw new SCLeccezione("errore-getFirstElement");
		else return (Integer) nodoinit.getInfo();		
	}
	public void print () throws SCLeccezione {
    	if (!this.empty()) {
		  Nodo aux=this.nodoinit;
		  while (aux != null) {
		  	System.out.println(aux.getInfo());
          	aux=aux.getNext();
		  }
      }
	}
  public static IntegerSCL readbSCL (BufferedReader br)
                            throws SCLeccezione, IOException {
      IntegerSCL aux = new IntegerSCL ();
      String o = br.readLine();
      while (o != null){
        Integer intobj;
        try {
           intobj = new Integer(Integer.parseInt(o));
        }
        catch (NumberFormatException e) {
           o = br.readLine(); continue;
        }
        aux.addElement(intobj);
        o = br.readLine();
      }
      return aux;
   }
   public static IntegerSCL readfSCL (BufferedReader br)
                            throws SCLeccezione, IOException {
      String o = br.readLine();
      if (o == null)
         return new IntegerSCL ();
      else {
         Integer intobj;
         try {
            intobj = new Integer(Integer.parseInt(o));
         }
         catch (NumberFormatException e) {
            return readfSCL(br);
         }
         IntegerSCL intSCL =  readfSCL(br);
         intSCL.addElement(intobj);
         return intSCL;
      }
  }
  public static void main(String[] args) throws IOException, SCLeccezione {
          FileInputStream filein =
            new FileInputStream (new File ("testIntegerSCL.txt"));
          BufferedReader br =
            new BufferedReader(new InputStreamReader(filein));

          IntegerSCL l1 = readfSCL(br);
	  l1.print();

//	  System.out.println(l1.countElements("Anna"));

//        IntegerSCL l2 = l1.copia();
//	  l2.print();

//	  l1.insertBefore("Anna","Daniele");
//	  l1.stampaSCL();

//	  l1.removeElement(30);
//	  l1.stampaSCL();

//	  l1.removeElement(2);
//	  l1.print();

//	  l1.remove("Anna");
//	  l1.print();

//	  l1.remove("pippo");
//	  l1.print();
	}
}

