Advertisement
Guest User

Untitled

a guest
Mar 27th, 2016
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. public class Stos
  2. {
  3. /* wierzcholek stosu */
  4. String start;
  5.  
  6. Stos()
  7. {
  8. start=null;
  9. }
  10.  
  11. /* zwracam wartosc wierzcholka */
  12. public String peek()
  13. {
  14. return start;
  15. }
  16.  
  17. /* dodaje element do stosu */
  18. public String push(String x)
  19. {
  20. String temp = x;
  21. start=temp;
  22. return start;
  23. }
  24.  
  25. /* sciagam element ze stosu */
  26. public String pop()
  27. {
  28. String temp;
  29. if(start!=null)
  30. {
  31. start = temp;
  32. start = start.getNext();//tu jest problem z getNext, jak to zrobić dla Stringa ?
  33. return temp;
  34. } else {
  35. System.out.println("Stos jest pusty");
  36. return null;
  37. }
  38.  
  39. }
  40.  
  41. /* wyswietlam zawartosc stosu */
  42. public void show()
  43. {
  44. if(start!=null)
  45. {
  46. while(start!=null)
  47. {
  48. System.out.print(start + " ");
  49. temp=temp.getNext(); // tutaj to samo
  50. }
  51. System.out.println();
  52. } else {
  53. System.out.println("Stos jest pusty");
  54. }
  55. }
  56.  
  57. /* zwracam ile elementow jest na stosie */
  58. public int zlicz()
  59. {
  60. if(start!=null)
  61. {
  62. String temp = start;
  63. int licznik=0;
  64. while(temp!=null)
  65. {
  66. licznik++;
  67. temp = temp.getNext(); //i tu
  68. }
  69. return licznik;
  70. }
  71. else return 0;
  72. }
  73. public boolean czyPusty()
  74. {
  75. if(start!=null){
  76. return false;
  77. }else{
  78. return true;
  79. }
  80. }
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement