1 / 8

Lab 6

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.

baris
Download Presentation

Lab 6

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  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 specifcsize (where applicable) based on the value of size received from the constructor.

  7. Methods • void push ( Object newElement) • Object pop ( ) • void clear ( ) • booleanisEmpty ( ) • booleanisFull ( ) • 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

More Related