p13 stack queue

Upload: abhishek-ek

Post on 06-Apr-2018

225 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/3/2019 P13 Stack Queue

    1/23

  • 8/3/2019 P13 Stack Queue

    2/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

  • 8/3/2019 P13 Stack Queue

    3/23

    DATA STRUCTURE

    Linear

    Array

    Linked list

    Stack

    Queue

    Non-linearTree

    Graphs

  • 8/3/2019 P13 Stack Queue

    4/23

  • 8/3/2019 P13 Stack Queue

    5/23

    STACK

    Stack is an ordered collection of

    items into which new items may be

    inserted and from which items maybe deleted at one end, called the

    top of the stack.

    A

    B

    C

    D

    E

  • 8/3/2019 P13 Stack Queue

    6/23

    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 ofstack

  • 8/3/2019 P13 Stack Queue

    7/23

    STACK

    A

    B

    C

    A

    B

    C

    D

    E

    A

    B

    C

    D

    A

    B

    C

    D

    A

    B

    C

    Push Push Pop Pop

    top

    top

    top

    top

    top

    LIFO

  • 8/3/2019 P13 Stack Queue

    8/23

    STACK

    Operations on stack

    Push

    Insert an item into stackFullstack()

    Check whether the stack is full or not

    Pop

    Remove an item from the stack

    Emptystack()

    Check whether the stack is empty or

    not

  • 8/3/2019 P13 Stack Queue

    9/23

    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

  • 8/3/2019 P13 Stack Queue

    10/23

    STACK-POP

    PERFORMS THE FOLLOWING

    OPERATIONS

    If the stack is empty, print a warning

    message and halt execution

    Remove the top element from thestack

    Return this element to the calling

    program

  • 8/3/2019 P13 Stack Queue

    11/23

    STACK

    11

    Stack-allocated memory

    When a function is called, memory isallocated for all of its parameters and local

    variables.

    Each active function call has memory on the

    stack (with the current function call on top)

  • 8/3/2019 P13 Stack Queue

    12/23

    STACK

    When a function call terminates,

    the memory is de-allocated

    (freed up)

    Ex:main() calls f(),

    f() calls g()

    g() recursively calls g()main()

    f()

    g()

    g()

  • 8/3/2019 P13 Stack Queue

    13/23

  • 8/3/2019 P13 Stack Queue

    14/23

    QUEUE

    Queue is an ordered collection of

    items from which items may be

    deleted at one end and into whichitems may be inserted at the other

    end

    Front-For deletion

    Rear-For insertion A B C

    FRONT

    REAR

  • 8/3/2019 P13 Stack Queue

    15/23

    QUEUE

    A B C

    FRONT

    B C

    FRONT

    B C

    FRONT

    REA

    R

    REAR

    REAR

    D E

    FIFO

  • 8/3/2019 P13 Stack Queue

    16/23

    QUEUE-INSERT

    Inserted at the rearend

    PERFORMS THE FOLLOWING

    ACTIONSCheck whether the queue is overflow

    or not

    Insert the element in the rear end ofqueue

  • 8/3/2019 P13 Stack Queue

    17/23

    QUEUE-DELETE

    Elements removed from the front end

    of the queue.

    PERFORMS THE FOLLOWINGACTIONS

    Check whether the queue is underflow

    or not

    Remove the front element from the

    queue

    Return this element to the calling

    program

  • 8/3/2019 P13 Stack Queue

    18/23

    QUEUE

    INITIALIZING

    queue[5]

    front=0,rear=0

    void add(int)

    int del()

  • 8/3/2019 P13 Stack Queue

    19/23

    QUEUE-INSERT

    If Rear>5

    Queue overflow

    Else

    Insert element into queue

    B C

    FRONT

    REAR

    D E

  • 8/3/2019 P13 Stack Queue

    20/23

    QUEUE-DELETE

    If front=rear

    Queue underflow

    Else

    Return queue[front] element

    B C

    FRONT

    REAR

    D E

  • 8/3/2019 P13 Stack Queue

    21/23

    QUEUE

    Task scheduler

    I/OBuffering

  • 8/3/2019 P13 Stack Queue

    22/23

    I request Electronics and communication

    ENGINEERING students to visit my blogfor

    more

    abhishek1ek.blogspot.com

    awhengineering.blogspot.com

  • 8/3/2019 P13 Stack Queue

    23/23