80 likes | 224 Views
Lab 6. Stack ADT. OVERVIEW. The stack is one example of a constrained linear data structure. In a stack, the elements are ordered from most recently added (the top) to the least recently added (the bottom). OVERVIEW. This is an example of a Stack:. Elements.
E N D
Lab 6 Stack ADT
OVERVIEW • The stack is one example of a constrained linear data structure. In a stack, the elements are ordered from most recently added (the top) to the least recently added (the bottom).
OVERVIEW • This is an example of a Stack:
Elements • The elements in a stack are of generic type Object.
Structure • The stack elements are linearly ordered from most recently added (the top) to least recently added (the bottom). Elements are inserted onto (pushed) and removed from (popped) the top of the stack.
Constructors • Stack ( ) Precondition: None. Postcondition: Default Constructor. Calls setup, which creates an empty stack and (if necessary) allocates enough memory for a stack containing DEF_MAX_STACK_SIZE (a constant value) elements. • Stack (int size) Precondition: size > 0. Postcondition: Constructor. Calls setup, which creates an empty stack and (if necessary) allocates enough memory for a stack containing size elements. • void setup(int size) Precondition: size > 0. A helper method for the constructors. Is declared private since only stack constructors should call this method. Postcondition: Creates an empty stack of a specifcsize (where applicable) based on the value of size received from the constructor.
Methods • void push ( Object newElement) • Object pop ( ) • void clear ( ) • booleanisEmpty ( ) • booleanisFull ( ) • void showStructure ( )
You should .. • Implement the operations in the StackNode ADT and the LStack ADT using a singly linked list to store the stack elements. Each node in the linked list should contain a stack element and a reference to the node containing the next element in the stack (next). • Your implementation also should maintain a reference to the node containing the topmost element in the stack (top). Base your implementation on the incomplete class definitions in the • files LStack.java and StackNode.java. • Send me two java files • LStack class • StackNode class • It should be complete. • Submit by email before your lab time