Introduction to stacks

what is a stack?

the stack is one type of linear data structure. the elements in the stack are removed or ca be added only through one end, so stacks are called as LIFO (Last-In-First-Out) data structure, the element which is inserted at the last, that element can be deleted first

let’s look into the real world example

introduction to stacks

in the above examples, there are a stack of chairs, the user first inserted yellow chair and last chair will be brown, if the user wants to remove the orange chair, first brown and then the blue chair should be removed, user cant removed any middle chair without removing its above chairs

Applications of stacks

  • UNDO and REDO
  • Backtracking
  • Memory management
  • Expression Conversion like prefix, postfix, infix
  • Parsing

stacks visual in data structures

introduction to stacks

same as the example of chairs,now we have a starting node xx22e is its address ,so attach a head pointer

head node has a next address of xx2f so its points to the next address

xx2f node has a next address xx2g, now last node doesnt have any next address so its null marked as X

image is provided in left slide

Last updated on by vishal devxo