| czart 
 
 
 Dołączył: 02 Mar 2007
 Posty: 168
 Przeczytał: 0 tematów
 
 Ostrzeżeń: 0/5
 Skąd: Z lasu
 
 | 
			
				|  Wysłany: Sob 20:49, 10 Lis 2007    Temat postu: |  |  
				| 
 |  
				| To i jeszcze ja dorzuce stos na niby-liście 
 
 
  	  | Kod: |  	  | package listy;
 import java.util.*;
 
 public class Stos
 {
 public Stos(int ile)
 {
 pierwszy = null;
 Random rand = new Random();
 for(int i = 0;i<ile;i++)
 push(rand.nextInt(20));
 }
 
 public void pop()
 {
 if (pierwszy!=null)
 pierwszy = pierwszy.nast;
 }
 
 public void push(int l)
 {
 Elem tmp = pierwszy;
 pierwszy = new Elem(l,tmp);
 }
 
 public int top()
 {
 if (pierwszy!=null)
 return pierwszy.d;
 else return -1;
 }
 
 public boolean empty()
 {
 if(pierwszy==null) return true;
 return false;
 }
 
 public void wypisz()
 {
 Elem tmp = pierwszy;
 while(tmp!=null)
 {
 System.out.print(tmp.d+" ");
 tmp=tmp.nast;
 }
 System.out.println();
 }
 
 private Elem pierwszy;
 }
 
 | 
 
 Element:
 
 
  	  | Kod: |  	  | public class Elem
 {
 public Elem(int l, Elem top)
 {
 nast = top;
 d = l;
 }
 
 public int d;
 public Elem nast;
 }
 
 | 
 |  |