Stack: Difference between revisions
Jump to navigation
Jump to search
Line 5: | Line 5: | ||
=Overview= | =Overview= | ||
A '''stack''' is a [[Data_Structures#Dynamic_Set|dynamic set]] in which the the [[Data Structures#DELETE|DELETE]] operation, which does not have any argument, removes the most recently inserted element. The stack | A '''stack''' is a [[Data_Structures#Dynamic_Set|dynamic set]] in which the the [[Data Structures#DELETE|DELETE]] operation, which does not have any argument, removes the most recently inserted element. The stack implements a ''last-in-first-out'', or LIFO, policy. Also see [[Queue#Overview|Queue]]. The [[Data Structures#INSERT|INSERT]] operation for a stack is called PUSH. The [[Data Structures#DELETE|DELETE]] operation is called POP. | ||
If the stack contains no elements it is said to be empty. If POP() operation is invoked on an empty stack, we say that the stack underflows. If PUSH() operation is called on a full stack, we say that the stack overflows. | |||
=Implementation= | =Implementation= | ||
The following code shows how to implement a simple stack of ints, backed by an integer array. | The following code shows how to implement a simple stack of ints, backed by an integer array. |
Revision as of 03:27, 11 August 2018
Internal
Overview
A stack is a dynamic set in which the the DELETE operation, which does not have any argument, removes the most recently inserted element. The stack implements a last-in-first-out, or LIFO, policy. Also see Queue. The INSERT operation for a stack is called PUSH. The DELETE operation is called POP.
If the stack contains no elements it is said to be empty. If POP() operation is invoked on an empty stack, we say that the stack underflows. If PUSH() operation is called on a full stack, we say that the stack overflows.
Implementation
The following code shows how to implement a simple stack of ints, backed by an integer array.