This is 'Palindrome Stack' assignment of
Data Structures (SPPU SE SEM-3) - CS of
Savitribai Phule Pune University - Gyaani Buddy
Stack-basics:
Stack is a linear data structure which follows LIFO(Last In First Out) or FILO(First In Last Out).
We maintain a variable called 'top' initialized to -1 initially when the stack is empty.
It is implemented using array or linked list.
Inserting an element to the top of stack is called-"push".
Deleting an element from the top of the stack is called-"pop".
In array implementation of stack, we restrict the insert and delete operations so that stack LIFO is followed.
Push method:
We increment the top variable and insert the element in the top-index of array.
So at any time, top will always indicate the index of the uppermost element of stack i.e.last inserted element.(You can refer to method implementation in code section).
Pop method:
We decrement the top.And automatically the topmost element gets deleted.
(You can refer to method implementation in code section).
Underflow Condition:
It is a condition when we try to delete an element from an empty stack.
So if(top==-1),the stack is empty and deletion can't be performed.
Overflow Condition:
It is a condition in which we try to insert an element in a stack which is full.
So if(top==(size of stack-1))-->[here size-1 indicates array implementaton as array index starts at 0] , stack is full and insertion can't be performed.
Palindrome String:
The string that reads the same backward as well as forward is called as palindrome string.
Eg: MadaM.
Algorithm to reverse a string and check if palindrome using stack is as follows:
1) Create an empty stack.
2) Push all characters of string one by one to stack.
3) Pop all characters one by one from stack and put
them into a new string.(reversed string)
4)Compare the new string and original string.
If they are equal-->String is palindrome.
If they are not equal-->String is not palindrome.
This is 'Palindrome Stack' assignment of
Data Structures (SPPU SE SEM-3) - CS of
Savitribai Phule Pune University - Gyaani Buddy
Coming soon