Data Structures
A data structure is a
particular way of
organizing data in a
computer so that it can
be used effectively
It is a logical way of
storing data and it
also defines
mechanism of
retrieving data
Stack
A stack is called a last-in-first-out (LIFO) collection.
This means that the last thing we added (pushed) is
the first thing that gets pulled (popped) off
A stack is a sequence of items that are
accessible at only one end of the sequence
A Stack is a list of elements in which an element
may be inserted or deleted at one end which is
known as TOP of the stack
Basic Operations that can be performed on
STACK:
TOP = -1, if stack index starts from 0
TOP = 0, if stack index starts from 1
Push and Pop Operations on Stack
PUSH OPERATION
POP OPERATION
Insertion(a, top, item, max)
If top = max then
print ‘STACK OVERFLOW’
exit
else
top = top+1
end if
a[top] = item
Exit
ALGORITHM OF INSERTION IN STACK: (PUSH)
Deletion(a, top, item)
If top = 0 then
print ‘STACK UNDERFLOW’
exit
else
item = a[top]
end if
top = top-1
Exit
ALGORITHM OF DELETION IN STACK: (POP)
Applications of Stacks
Reversing Strings
Expression Evaluation.
Recursion handling
Check Parenthesis matching in an expression
Page-visited history in a Web browser
Undo sequence in a text editor etc.
THANK YOU

Ds stacks

  • 1.
  • 2.
    A data structureis a particular way of organizing data in a computer so that it can be used effectively It is a logical way of storing data and it also defines mechanism of retrieving data
  • 3.
  • 4.
    A stack iscalled a last-in-first-out (LIFO) collection. This means that the last thing we added (pushed) is the first thing that gets pulled (popped) off A stack is a sequence of items that are accessible at only one end of the sequence A Stack is a list of elements in which an element may be inserted or deleted at one end which is known as TOP of the stack
  • 6.
    Basic Operations thatcan be performed on STACK:
  • 7.
    TOP = -1,if stack index starts from 0 TOP = 0, if stack index starts from 1
  • 8.
    Push and PopOperations on Stack
  • 9.
  • 10.
  • 14.
    Insertion(a, top, item,max) If top = max then print ‘STACK OVERFLOW’ exit else top = top+1 end if a[top] = item Exit ALGORITHM OF INSERTION IN STACK: (PUSH)
  • 15.
    Deletion(a, top, item) Iftop = 0 then print ‘STACK UNDERFLOW’ exit else item = a[top] end if top = top-1 Exit ALGORITHM OF DELETION IN STACK: (POP)
  • 16.
    Applications of Stacks ReversingStrings Expression Evaluation. Recursion handling Check Parenthesis matching in an expression Page-visited history in a Web browser Undo sequence in a text editor etc.
  • 17.