Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 23

DATA STRUCTURE

Representation of data and the operations allowed on that data. For organizing and storing data in an ordered and controlled way. Two types  Linear  Non-linear

DATA STRUCTURE
Linear  Array  Linked list  Stack  Queue Non-linear  Tree  Graphs

STACK
Stack is an ordered collection of items into which new items may be inserted and from which items may be deleted at one end, called the top of the stack.
E D C B A

STACK
Unlike array, definition of stack provides insertion and deletion of items Single end of the stack is designed as the stack top New items are placed on top of stack

STACK

E D C B A top C B A Push top D C B A Push

top D C B A Pop top C B A Pop top

LIFO

STACK

Operations on stack  Push

Insert an item into stack Fullstack() Check whether the stack is full or not


Pop

Remove an item from the stack Emptystack() Check whether the stack is empty or not

STACK-PUSH

PERFORMS THE FOLLOWING ACTIONS


 If

the stack is full, print a warning message and halt execution  Insert an element on top of stack

STACK-POP

PERFORMS THE FOLLOWING OPERATIONS


 If

the stack is empty, print a warning message and halt execution  Remove the top element from the stack  Return this element to the calling program

STACK
Stack-allocated memory
 When

a function is called, memory is allocated for all of its parameters and local variables.  Each active function call has memory on the stack (with the current function call on top)

11

STACK
 When

a function call terminates, the memory is de-allocated (freed up)


g()

Ex:main()

calls f(), f() calls g() g() recursively calls g()

g() f() main()

QUEUE
Queue is an ordered collection of items from which items may be deleted at one end and into which items may be inserted at the other end FRONT Front-For deletion A B C Rear-For insertion

REAR

QUEUE
FRONT A B C REAR FRONT FIFO B C REAR FRONT B C D E REAR

QUEUE-INSERT
Inserted at the rear end PERFORMS THE FOLLOWING ACTIONS
 Check

whether the queue is overflow

or not  Insert the element in the rear end of queue

QUEUE-DELETE
Elements removed from the front end of the queue. PERFORMS THE FOLLOWING ACTIONS
 Check

whether the queue is underflow

or not  Remove the front element from the queue  Return this element to the calling program

QUEUE

INITIALIZING queue[5] front=0,rear=0 void add(int) int del()

QUEUE-INSERT
If Rear>5 Queue overflow Else Insert element into queue
FRONT B C D E REAR

QUEUE-DELETE
If front=rear Queue underflow Else Return queue[front] element
FRONT B C D E REAR

QUEUE
Task scheduler I/O Buffering

I request Electronics and communication ENGINEERING students to visit my blog for more abhishek1ek.blogspot.com awhengineering.blogspot.com

You might also like