Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Stos
- {
- /* wierzcholek stosu */
- String start;
- Stos()
- {
- start=null;
- }
- /* zwracam wartosc wierzcholka */
- public String peek()
- {
- return start;
- }
- /* dodaje element do stosu */
- public String push(String x)
- {
- String temp = x;
- start=temp;
- return start;
- }
- /* sciagam element ze stosu */
- public String pop()
- {
- String temp;
- if(start!=null)
- {
- start = temp;
- start = start.getNext();//tu jest problem z getNext, jak to zrobić dla Stringa ?
- return temp;
- } else {
- System.out.println("Stos jest pusty");
- return null;
- }
- }
- /* wyswietlam zawartosc stosu */
- public void show()
- {
- if(start!=null)
- {
- while(start!=null)
- {
- System.out.print(start + " ");
- temp=temp.getNext(); // tutaj to samo
- }
- System.out.println();
- } else {
- System.out.println("Stos jest pusty");
- }
- }
- /* zwracam ile elementow jest na stosie */
- public int zlicz()
- {
- if(start!=null)
- {
- String temp = start;
- int licznik=0;
- while(temp!=null)
- {
- licznik++;
- temp = temp.getNext(); //i tu
- }
- return licznik;
- }
- else return 0;
- }
- public boolean czyPusty()
- {
- if(start!=null){
- return false;
- }else{
- return true;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement