SHARE
TWEET

Untitled

a guest Oct 21st, 2019 67 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.  * To change this license header, choose License Headers in Project Properties.
  3.  * To change this template file, choose Tools | Templates
  4.  * and open the template in the editor.
  5.  */
  6. package stos;
  7.  
  8. /**
  9.  *
  10.  * @author Hubert
  11.  */
  12. public class Stos implements IStos{
  13.  
  14. private Element top;
  15.  
  16. public Stos(){
  17. top=null;
  18. }
  19.  
  20.  
  21.     public static void main(String[] args) {
  22.         Stos s=new Stos();
  23.         s.push(5);s.push(4);s.push(3);
  24.         System.out.println("Wartosc na wierzcholku: "+s.peek());
  25.         s.print();
  26.         System.out.println("w: "+s.pop());
  27.          s.print();
  28.         //s.clear();
  29.         System.out.println(s.isEmpty());
  30.     }
  31.  
  32.     @Override
  33.     public void push(int i) {
  34.         Element nowy=new Element();
  35.         nowy.dane=i;
  36.         nowy.next=top;
  37.         top=nowy;
  38.   }
  39.  
  40.     @Override
  41.     public int pop() {
  42.         if(isEmpty())
  43.             return 0;
  44.        
  45.     int x=top.dane;
  46.     top=top.next;
  47.     return x;
  48.     }
  49.  
  50.     @Override
  51.     public int peek() {
  52.         int x=top.dane;
  53.         return x;
  54.     }
  55.  
  56.     @Override
  57.     public boolean isEmpty() {
  58.         if(top==null)
  59.             return true;
  60.         else
  61.             return false;
  62.    }
  63.  
  64.     @Override
  65.     public void print() {
  66.         int x;
  67.         Element pomoc=top;
  68.         while(pomoc!=null){
  69.            x=pomoc.dane;
  70.         System.out.println("Wartosc: "+x);
  71.         pomoc=pomoc.next;
  72.        
  73.         }
  74.    
  75.     }
  76.  
  77.     @Override
  78.     public void clear() {
  79.         while(top!=null){
  80.         top=null;
  81.         top=top.next;
  82.         }
  83.  }
  84.    
  85. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top