blob: 613f9f237a5559ee37748357637f91d43335f4b1 (
plain)
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
|
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;
}
}
|