public class LinkedStack
1: import java.util.EmptyStackException;
2: /**
3: A class of stacks whose entries are stored in a chain of nodes.
4: @author Frank M. Carrano and Timothy M. Henry
5: @version 4.0
6: */
7: public class LinkedStack<T> implements StackInterface<T>
8: {
9: private Node topNode; // References the first node in the chain
10:
11: public LinkedStack()
12: {
13: topNode = null;
14: } // end default constructor
15:
16: // < Implementations of the stack operations go here. >
17: // . . .
18:
19: private class Node
20: {
21: private T data; // Entry in stack
22: private Node next; // Link to next node
23:
24: private Node(T dataPortion)
25: {
26: this(dataPortion, null);
27: } // end constructor
28:
29: private Node(T dataPortion, Node linkPortion)
30: {
31: data = dataPortion;
32: next = linkPortion;
33: } // end constructor
34:
35: private T getData()
36: {
37: return data;
38: } // end getData
39:
40: private void setData(T newData)
41: {
42: data = newData;
43: } // end setData
44:
45: private Node getNextNode()
46: {
47: return next;
48: } // end getNextNode
49:
50: private void setNextNode(Node nextNode)
51: {
52: next = nextNode;
53: } // end setNextNode
54: } // end Node
55: } // end LinkedStack