Stack

  • November 2019
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View Stack as PDF for free.

More details

  • Words: 312
  • Pages: 11
Stack A stack is a constrained version of a linked list New nodes can be added to the stack and removed from stack only at the top.  Stack is referred as Last-in First-Out (LIFO)data Structure. Primary methods are used to manipulate stack are push and pop methods Push method adds a new node to the top of the stack Pop method removes node from top of stack

Stack Primitive operations on stack : Create a stack Insert an element on to the stack Delete an element from stack Check whether stack is empty Check which element is on top of stack

Stack Stack Empty operations : int stempty() { if(st.top == -1) return 1; else return 0; }

Stack Stack Full operations : int stfull() { if(st.top >= size-1) return 1; else return 0; }

Stack Stack push operations : void push(int item) { st.top++; st.s[st.top]=item; }

Stack Stack pop operations : int pop() { int item; item = st. s[st.top]; st.top --; return(item); }

Stack-push stack=empty ,top=-1

top

10

Pushed 10 on stack, stack top is=0

20

top

10 Pushed 20 on stack, stack top is=1

Stack-pop

20

top

10

top

10

Poped 20 on stack, stack top is=0 Poped 10 on stack, stack top is= -1

stack empty

Stack-Applications Expression Conversion Expression Evaluation Parsing well formed parenthesis Decimal to binary conversion Reversing a string

Queue Queue can be defined as ordered collection of elements that has two ends front and rear from front one can delete elements from rear one can add elements

front

rear

Trees Tree is a nonlinear data structure Tree node contains 2 or more links Root node is first node in tree each link in root node refers child node left child is first node in left sub tree right child is first node in right sub tree in-order,pre-order,post-order are traversal techniques for binary tree.

Related Documents

Stack
May 2020 16
Stack
April 2020 21
Stack
June 2020 14
Stack
November 2019 19
Stack
November 2019 19
Stack
December 2019 22