1.

Write a short note on stack.

Answer»

A stack is an ordered collection of items in which data items may be inserted and deleted at one end. This end is referred as “top”. The opposite to top is known as “base”. The most recently added item in the stack is removed first. This working principle is sometimes called LIFO (Last In First Out). Newer inserted elements will be near the top and elements that are inserted at the beginning are near the base.

The applications of stack:

  • Arithmetic Expression evaluation
  • Arithmetic Expression conversion
  • Recursive function .
  • Backtracking (game playing, finding paths, exhaustive searching)
  • Memory management, run-time environment for nested language features.

The operation on stack is

  • stack() creates a new empty stack,
  • push(item) insert new item at the top of stack,
  • pop() removes the top element from the stack,
  • peek() returns the top item of the stack,
  • Empty() checks the stack is empty or not and
  • size() returns number of items present in the stack


Discussion

No Comment Found

Related InterviewSolutions