Explain the operation performed on stack
Answers
Answered by
2
Stack Operations
The two operations that form the majority of the functionality of the stack are the operation of adding to the stack, and the operation of removing items from the stack.
For historical reasons the operation of adding items to a stack is called push. For similar reasons the operation of removing an item from a stack is usually referred to as pop.
There are a couple more operations that we must consider before we attempt to implement a stack. The first of these is an operation called init. This initialises the stack, and ensures that state of the software is in a known condition before we try to use it. Just about every structure that we will ever use will require an initialisation routine - get into the habit of writing the outline of the init operation first!
As this is a course in developing software, we must also consider the possibility of errors. The easiest error to envisage for a stack is when a program tries to remove an item from an empty stack. This condition is called overflow, and if undetected will probably cause a series of mysterious errors before the program crashes. The method that we use to detect this problem is to use an operation called isEmpty to tell us if the stack is empty. If we try and take data from an empty stack the error condition is usually called underflow. Similarly there is a possibility that we might run out of space. To counter this we can provide an operation called isFull.
Using this analysis we can conclude that we need to provide five operations to implement a stack. These operations are:
1) init
2) isEmpty
3) isFull
4) push
5) pop
If we can satisfactorily implement these operations we have implemented a stack.
Hope it will you.. Please mark as brainliest if you have understood this.
The two operations that form the majority of the functionality of the stack are the operation of adding to the stack, and the operation of removing items from the stack.
For historical reasons the operation of adding items to a stack is called push. For similar reasons the operation of removing an item from a stack is usually referred to as pop.
There are a couple more operations that we must consider before we attempt to implement a stack. The first of these is an operation called init. This initialises the stack, and ensures that state of the software is in a known condition before we try to use it. Just about every structure that we will ever use will require an initialisation routine - get into the habit of writing the outline of the init operation first!
As this is a course in developing software, we must also consider the possibility of errors. The easiest error to envisage for a stack is when a program tries to remove an item from an empty stack. This condition is called overflow, and if undetected will probably cause a series of mysterious errors before the program crashes. The method that we use to detect this problem is to use an operation called isEmpty to tell us if the stack is empty. If we try and take data from an empty stack the error condition is usually called underflow. Similarly there is a possibility that we might run out of space. To counter this we can provide an operation called isFull.
Using this analysis we can conclude that we need to provide five operations to implement a stack. These operations are:
1) init
2) isEmpty
3) isFull
4) push
5) pop
If we can satisfactorily implement these operations we have implemented a stack.
Hope it will you.. Please mark as brainliest if you have understood this.
Similar questions