Abstract Data Types (ADT)
Abstract Data type (ADT) is a type (or class) for objects whose behavior is defined by a set of value and a set of operations.
The definition of ADT only mentions what operations are to be performed but not how these operations will be implemented. It does not specify how data will be organized in memory and what algorithms will be used for implementing the operations. It is called “abstract” because it gives an implementation-independent view. The process of providing only the essentials and hiding the details is known as abstraction.
The Stack Abstract Data Type
The stack abstract data type is defined by the following structure and operations. A stack is structured, as described above, as an ordered collection of items where items are added to and removed from the end called the “top.” Stacks are ordered LIFO. The stack operations are given below.
Stack()
creates a new stack that is empty. It needs no parameters and returns an empty stack.push(item)
adds a new item to the top of the stack. It needs the item and returns nothing.pop()
removes the top item from the stack. It needs no parameters and returns the item. The stack is modified.peek()
returns the top item from the stack but does not remove it. It needs no parameters. The stack is not modified.isEmpty()
tests to see whether the stack is empty. It needs no parameters and returns a boolean value.size()
returns the number of items on the stack. It needs no parameters and returns an integer.
# Main operations
push(element) -> Add an element to the top
pop() -> Remove the element from the top
peek() -> See what is the element in the top
isEmpty() -> Check if the stack is empty