





























Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!






























III. Specify an abstract data type for the software stack
I. Create a design specification for the data structure and explain what valid operations can be performed on the structure
II. What is the stack data type? Operations on the stack data type
Abstract Data type (ADT) is a type (or class) for objects whose behaviour is defined by a set of value and a set of operations.
Before a program can be written, the programmer must know what tasks the program does. The inputs and outputs of each task must be clearly defined from the outset. Also decide which data structure to use to be most efficient in terms of time and space. An items that specifies operations is called an abstract data type. In Java, ADT can be part of a program as an interface.
ADT example: LIST ADT
Stack is an abstract data structure that operates on the Last In First Out (LIFO) principle. That is, the last element inserted on the stack will be the first element removed from the stack.
The stack data structure is limited in the same way as above. Thus, our stack manipulation includes only the following actions:
Push: Add an element to the top of the stack, the number of elements of the stack increases by 1. Pop: Removes the first element at the top of the stack, the number of elements on the stack is reduced by 1. Top: Get the value of the first element at the top of the stack, the number of elements of the stack does not change. IsEmpty: Check if the stack is empty or not. An empty stack is a stack with no elements. IsFull: Checks whether the stack is full or not. This action is not always available. Size: Gets the number of stack elements available.
Code demo Push
Pop Operation Accessing the content while removing it from the stack, is known as a Pop Operation. In an array implementation of pop() operation, the data element is not actually removed, instead top is decremented to a lower position in the stack to point to the next value. But in linked-list implementation, pop() actually removes data element and deallocates memory space. A Pop operation may involve the following steps โ