public class KStack { private KNode head; private int length; public KStack() { length = 0; } public int[] peek() { return head.getData(); } public int[] pop() { int[] output = head.getData(); head = head.getNext(); length--; return output; } public void push(int[] i) { head = new KNode(i,head); length++; } public boolean hasNext() { return head != null; } public int getLength() { return length; } public String toString() { String output = ""; for(KNode tmp = head; tmp != null; tmp=tmp.getNext()) { output += tmp.getData() + " "; } return output; } public int[][] toArray() { int[][] output = new int[length][4]; int i = length-1; for(KNode tmp = head; tmp != null; tmp = tmp.getNext()) { output[i] = tmp.getData(); i--; } return output; } }