هياكل البيانات - الطابور

  • Published on
    15-Jul-2015

  • View
    695

  • Download
    15

Embed Size (px)

Transcript

  • . ..

    1

    eueuQ

    .. ,

    . ( .

    ) .

    .

    ): 1(

    . ,

    .

    , ,

    . OFIF ))OFIF( tuO tsriF nI tsriF(

    , .

  • . ..

    2

    , , ,

    ....

    . ,

    , . .

    :

    .1 ,

    ( , ).

    .2 , ,

    . , .3

    ,

    . .4

    . .retuor , .5 .6

    . . .7

    erutcurts atad citats ,

    , erutcurts atad cimanyd

    . .

  • . ..

    3

    ): 2(

    :)(

    ,

    retnioP liaT ) ( retnioP daeH

    () . .

    ): 3(

    :

    .

    .

    .

  • . ..

    4

    ( ).

    :

    .

    .

    .

    .

    :

    ( , .1 . ,)

    : , .2 ( ) ( .A

    ). . .B

    )1-( .3 , )1-( (

    ).

    : , ) )1-( ( , .1

    . ) 1- ( .2

    : , ( .A

    .) , ) )1-( ( .3

    .

    :

    .

    )1-( .

    , 5 . .

  • .. .

    5

    (4 :)

    ..

    // Problem : Queue - Data Structure

    #include < iostream >

    #define QUEUE_SIZE 100

    using namespace std;

    class Queue {

    int q[QUEUE_SIZE];

    int first, last; int count;

    public:

    Queue();

    void enqueue(int x);

    int dequeue();

    int getSize();

    };

  • .. .

    6

    Queue::Queue()

    {

    first = 0;

    last = QUEUE_SIZE - 1;

    count = 0;

    }

    void Queue::enqueue(int x)

    {

    last = (last + 1) % QUEUE_SIZE;

    q[last] = x;

    count++;

    }

    int Queue::dequeue()

    {

    int x = q[first];

    first = (first + 1) % QUEUE_SIZE;

    count--;

    return x;

    }

    int Queue::getSize()

    {

    return count;

    }

    int main()

    {

    Queue q;

    q.enqueue(1);

    q.enqueue(2);

    q.enqueue(3);

    while (q.getSize())

    cout

  • . ..

    7

    ,

    .

    .

    )metIataD( eueuQ

    . )edoNtxeN (

    ): 5(

    ,

    .

    , :

    ,

    :

    ) (

    .

    . ) 1-(

    , , .

    . .

    . 5

    .

    ) (

    .

  • . ..

    8

    .

    .

    .

    n dom )1 + raer( = raeR

    n dom )1 + tnorf( = tnorF

    ): 6(

    :

    .

    ,

    .

    .

    ,

    , . .

    .

    .

  • . ..

    9

    .1

    )xam % )1+raer( = = tnorf( fi

    ,

    .A

    .B

    ) 1( .2

    xam % )1+raer( = raer

    .3

    ;tnemele = ]raer[Q

    , , )1-( .4

    ;0 = raer ;0 = tnorf ) 1- == tnorf( fI

    )1-( .1

    ))1- == raer( && )raer == tnorf(( fi

    .A

    .B

    .. ) 1( , .2

    ]tnorf[Q = tnemele

    .. .3

    ( .A

    )

    1- = raer=tnorf )raer == tnorf( fI

    )A( .B

    xam % )1 + tnorf( = tnorf

    ) 2( :

    ,

    ) 3 ,2( :

    )xam( .

    ,

  • . ..

    01

    (

    )

    ) 1(

    . ,

    . 5 . A

    26 ,24, 22

    :

    )1-( .1

    ): 7(

    21 25

  • . ..

    11

    ): 8(

    . 23

    ) (

    ))ezis % )1+ raer(( == tnorf ( fI

    0 = tnorF

    0 = 5 % )1+4( = ezis % )1 + raeR(

    ,

    )1- = raeR( && )raeR == tnorF( fI

    .

    ) ( )4 = raer && 0 = tnorf(

    ezis % )1 + tnorF( = tnorF

    5 % )1 + 0( =

    5 % 1 =

    1 = tnorF

  • . ..

    21

    ) : 9(

    ezis % )1 + tnorF ( = tnorF

    5 % ) 1+ 1( =

    5 % 2 =

    2 =

    ): 21(

    ): 11(

    2 raeR ,

    tnorf raer

  • . ..

    31

    ): 21(

    , ,

    raer 2 4

    . ) 31( 1

    ) : 31(

    ,

    54, 22

    ): 41(

  • . ..

    41

    ): 51(

    92, 77

    ): 61(

    >h.maertsoi< edulcni #

    >h.ssecorp< edulcni #

    >h.oinoc< edulcni #

    ;)(unem_yalpsid tni

    eueuqralucric ssalc

    {

    ;]01[rra tni

    ;raer,tnorf tni

    ;ezis tni

    :cilbup

    )(eueuqralucric

    {

    ;0=tnorf

    ;0=raer

    ;01=ezis

    }

    ;)(yalpsid diov

    ;)(eueuqne diov

  • .. .

    15

    void delete_element();

    };

    void circularqueue :: display()

    {

    cout

  • .. .

    16

    if(next==front)

    {

    cout

  • .. .

    17

    {

    case 1: cq1.enqueue();

    break;

    case 2: cq1.delete_element();

    break;

    case 3: cq1.display();

    break;

    case 4: exit(1);

    }

    }

    }

    int display_menu()

    {

    int c;

    clrscr();

    cout