Advertisement
olekturbo

ostatnie

May 22nd, 2017
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | None | 0 0
  1. import java.util.Scanner;
  2. class PustaLista extends Exception {
  3. public PustaLista(String str) { super(str);}
  4. }
  5.  
  6. class Lista {
  7.  
  8. private class Para {
  9. private String nap;
  10. private Para dal;
  11. public Para(String np, Para dl) { nap=np; dal=dl; }
  12. public String napis() { return nap; }
  13. public Para dalej() { return dal; }
  14. }
  15.  
  16. private Para par;
  17. public Lista() { par=null; }
  18.  
  19. public void dolacz(String str) { par = new Para(str,par); }
  20. public Boolean czyPusta() { return par==null; }
  21. public String pierwszy() throws PustaLista {
  22. if (par==null) throw new PustaLista("pierwszy nie istnieje");
  23. else return par.napis();
  24. }
  25. public void usun() throws PustaLista {
  26. if (par==null) throw new PustaLista("usun niewykonalne");
  27. else par=par.dalej();
  28. }
  29. }
  30. class App {
  31. public static void main(String[] args) throws PustaLista {
  32. Scanner sc = new Scanner(System.in);
  33. Lista lis = new Lista();
  34. String input;
  35. while(!((input = sc.nextLine()).equals(""))){
  36.  
  37. lis.dolacz(input);
  38.  
  39. }
  40. while(!lis.czyPusta()) {
  41. System.out.println(lis.pierwszy());
  42. lis.usun();
  43. }
  44.  
  45.  
  46. }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement