GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — programming/problems/stack/StackOfStrings.java at master · rp-code9/programming Expand file tree/ Copy pathStackOfStrings.javaMore file actions 64 lines (53 loc) · 1.28 KB / Copy pathStackOfStrings.javaFile metadata and controls64 lines (53 loc) · 1.28 KB 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 class StackOfStrings { private Node head; private int size; private class Node { String item; Node next; public Node(String s) { item = s; next = null; } } public StackOfStrings() { head = null; size = 0; } public boolean isEmpty() { return head == null; } public void push(String s) { Node temp = new Node(s); if (!isEmpty()) { temp.next = head; } head = temp; size++; } public String pop() { if (isEmpty()) { return null; } Node temp = head; head = head.next; temp.next = null; size--; return temp.item; } public int size() { return this.size; } public static void main(String[] args) { String[] strings = {"a", "b", "c", "d"}; StackOfStrings stack = new StackOfStrings(); System.out.println("Size : " + stack.size()); for (String s : strings) { stack.push(s); System.out.println("Size : " + stack.size()); } while (!stack.isEmpty()) { System.out.println("Pop : " + stack.pop()); } System.out.println("Size : " + stack.size()); } } |
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |