Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Element {
- int liczba;
- Element next;
- public Element(int liczba, Element next) {
- this.liczba = liczba;
- this.next = next;
- }
- public Element zwrocWskaznik() {
- return next;
- }
- public int zwrocLiczbe() {
- return liczba;
- }
- }
- public class Stos {
- Element head;
- int licznikStosu;
- public Stos() {
- head = null;
- licznikStosu = 0;
- }
- public void push(int x) {
- Element nowy = new Element(x, head);
- head = nowy;
- licznikStosu++;
- }
- public int pop() {
- if (head != null) {
- int ret = head.zwrocLiczbe();
- head = head.zwrocWskaznik();
- return ret;
- }
- return 0xffff;
- }
- public int zwrocLiczbeElementow() {
- return licznikStosu;
- }
- public static void main(String[] args) {
- Stos head = new Stos();
- head.push(1);
- head.push(2);
- head.push(3);
- System.out.println(head.pop());
- System.out.println(head.pop());
- System.out.println(head.pop());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment