Download presentation
Presentation is loading. Please wait.
Published byBridget Gallagher Modified over 9 years ago
1
Lab 6 Stack ADT
2
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).
3
OVERVIEW This is an example of a Stack:
4
Elements The elements in a stack are of generic type Object.
5
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.
6
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 specifc size (where applicable) based on the value of size received from the constructor.
7
Methods void push ( Object newElement ) Object pop ( ) void clear ( ) boolean isEmpty ( ) boolean isFull ( ) void showStructure ( )
8
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
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.