demo-queue-circular-array

Document Sample
demo-queue-circular-array Powered By Docstoc
					1
Queue ADT: circular
array implementation




                  2
        Queue ADT: circular
t       array implementation
    h

           enqueue(‘A’)




                          3
        Queue ADT: circular
    h   array implementation

             enqueue(‘D’)

A        t




                          4
        Queue ADT: circular
    h   array implementation

           enqueue(‘T’)

A


    D




               t




                          5
            Queue ADT: circular
    h       array implementation

               enqueue(‘E’)

A


    D



    T




        t
                              6
            Queue ADT: circular
        h   array implementation

               dequeue()

    A


        D



        T


    E


t
                              7
            Queue ADT: circular
            array implementation

               dequeue()

    A           h


        D



        T


    E


t
                              8
            Queue ADT: circular
            array implementation

               enqueue(‘X’)

    A


        D



        T
                    h
    E


t
                              9
                Queue ADT: circular
                array implementation

                   enqueue(‘A’)

        A


            D



            T
                        h
t
    X   E


                                 10
                    Queue ADT: circular
                    array implementation

                       enqueue(‘M’)

            A
t
                D



    A           T
                            h
        X   E


                                     11
                    Queue ADT: circular
    t               array implementation

                       enqueue(‘P’)

            A


M               D



A               T
                            h
        X   E


                                     12
                    Queue ADT: circular
            t       array implementation

                       enqueue(‘L’)

    P   A


M               D



A               T
                            h
    X   E


                                     13
                Queue ADT: circular
                array implementation

                   enqueue(‘E’)

    P   L           t


M           D



A           T
                        h
    X   E


                                 14
                Pointing t here will
                cause problems!
                When t==h, is queue
    P   L       empty or full?

                   Our circular array must be 1
                   cell larger than the # of
M           E      values it’s expected to
                   contain at any given time.




A           T
                               t


    X   E                 h




                                       15

				
DOCUMENT INFO
Categories:
Tags:
Stats:
views:5
posted:7/31/2012
language:French
pages:15