Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package stos;
- /**
- *
- * @author Hubert
- */
- public class Stos implements IStos{
- private Element top;
- public Stos(){
- top=null;
- }
- public static void main(String[] args) {
- Stos s=new Stos();
- s.push(5);s.push(4);s.push(3);
- System.out.println("Wartosc na wierzcholku: "+s.peek());
- s.print();
- System.out.println("w: "+s.pop());
- s.print();
- //s.clear();
- System.out.println(s.isEmpty());
- }
- @Override
- public void push(int i) {
- Element nowy=new Element();
- nowy.dane=i;
- nowy.next=top;
- top=nowy;
- }
- @Override
- public int pop() {
- if(isEmpty())
- return 0;
- int x=top.dane;
- top=top.next;
- return x;
- }
- @Override
- public int peek() {
- int x=top.dane;
- return x;
- }
- @Override
- public boolean isEmpty() {
- if(top==null)
- return true;
- else
- return false;
- }
- @Override
- public void print() {
- int x;
- Element pomoc=top;
- while(pomoc!=null){
- x=pomoc.dane;
- System.out.println("Wartosc: "+x);
- pomoc=pomoc.next;
- }
- }
- @Override
- public void clear() {
- while(top!=null){
- top=null;
- top=top.next;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement