-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStack.java
More file actions
44 lines (38 loc) · 889 Bytes
/
Copy pathStack.java
File metadata and controls
44 lines (38 loc) · 889 Bytes
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
/* *****************************************************************************
* Name: Rafael Neves Moraes
*
* Description: Stack algorithm Object Implementation.
*
* Written: 5/06/2019
*
* % javac Stack.java
* % java Stack
* Proposition. A stack with N items uses~ 40 N bytes.
*
**************************************************************************** */
public class Stack<Item>
{
private Node first = null;
private class Node
{
Item item;
Node next;
}
public boolean isEmpty()
{
return first == null;
}
public void push(Item item)
{
Node oldfirst = first;
first = new Node();
first.item = item;
first.next = oldfirst;
}
public Item pop()
{
Item item = first.item;
first = first.next;
return item;
}
}