Se ha denunciado esta presentación.
Utilizamos tu perfil de LinkedIn y tus datos de actividad para personalizar los anuncios y mostrarte publicidad más relevante. Puedes cambiar tus preferencias de publicidad en cualquier momento.
C
3:
.
1.
1.
2.
2.
1.
2. C:
3. C:
4. C: ! – "
#
5. C: $
%#
6. C:
%#
7. C: & !
3. "
1.
2. C:
3. C:
4. C: ! – "
5. C: ! – #
...
A.
2. *!"
1. ,
% ! # " ! ( ) ! :
• - ! N !
• ." (finish) ! "
• (, 0)
/"# C
a[0]
…
a[1] a[2] a[2] a[N-1]
finish=2
4 5 34 5 ...
5
A.
2. *!"
5. )" ! C: %
"
$ ! # finish+1 ( 2
)
/* QU_enqueue(): Eisagei to x stin oura q
* epistrefei TRUE: se periptwsi ...
A.
3. + "
1. + "
#
! ! !
, ! ! .
! ! . " . " "" ." !
." (
). / ! :
enqueue(2)
2
enqueue(4)
2 4
4
dequeue( )
enqueue(5)
4
e...
A.
3. + "
4. )" ! C: -" – +
#
! ." ! ." start ( ."
finish) -1
• * " ! ( 2 " ! . # !
! ! ! . " ! )
/* QU_empty(): epistrefe...
start=1
A.
3. + "
6. )" ! C: *! %
#
( ! # ) ! ( 2 ):
• *! start (# ! 2 )
:
• * start < ! QUEUE_SIZE-1, start=start+1
• * s...
(. *
,2 2:
! , ! ! !
! ! $ !
( " , " ! ).
- ! " ! « » :
1 ! ! $
! .
( .
! )
+ ! ! " ! ,
! ! # "" " project ! " .
)! :
• " ...
Próxima SlideShare
Cargando en…5
×

ΔΟΜΕΣ ΔΕΔΟΜΕΝΩΝ ΣΕ C - ΜΑΘΗΜΑ 3 (ΕΚΤΥΠΩΣΗ)

2.429 visualizaciones

Publicado el

.

Publicado en: Educación
  • Sé el primero en comentar

  • Sé el primero en recomendar esto

ΔΟΜΕΣ ΔΕΔΟΜΕΝΩΝ ΣΕ C - ΜΑΘΗΜΑ 3 (ΕΚΤΥΠΩΣΗ)

  1. 1. C 3: . 1. 1. 2. 2. 1. 2. C: 3. C: 4. C: ! – " # 5. C: $ %# 6. C: %# 7. C: & ! 3. " 1. 2. C: 3. C: 4. C: ! – " 5. C: ! – # 6. C: $ %# 7. C: %# 8. C: & ! . A. 1. 1. « » ! : • ! (enqueue) , " • ! (dequeue) , enqueue(2) 2 : • ! " # ! $ ! % & : • ' ! # ! ! ! # ! (First In – First Out: FIFO) enqueue(4) 2 4 4 dequeue( ) enqueue(5) 4 enqueue(3) 4 5 5 3 A. 1. 2. ( ' : • (init) • $ (enqueue) • ! (dequeue) • ! (empty) • ! (full) )! " ! : • ! ( ) • *!" ( ! ) • + " • !" " ( ! )
  2. 2. A. 2. *!" 1. , % ! # " ! ( ) ! : • - ! N ! • ." (finish) ! " • (, 0) /"# C a[0] … a[1] a[2] a[2] a[N-1] finish=2 4 5 34 5 3 A. 2. *!" 2. )" ! C: "# & C " : • (struct) : • - QUEUE_SIZE • ." (finish) ! " : • *! 0…QUEUE_SIZE-1 " • -1 . #define QUEUE_SIZE 10 /* Megethos pinaka ouras */ typedef int elem; /* typos dedomenwn ouras */ struct queue{ elem array[QUEUE_SIZE]; /* pinakas stoixeiwn */ int finish; /* telos tis ouras */ }; typedef struct queue QUEUE; /* Sinwnimo tis ouras */ … finish=2 2 6 4 * ! : 0 1 2 3 QUEUE_SIZE-1 array A. 2. *!" 3. )" ! C: * ! ! " -1 /* QU_init(): arxikopoiei tin oura */ void QU_init(QUEUE *q) { q->finish=-1; } … finish=?? 0&1: 0 1 2 3 QUEUE_SIZE-1 array … finish=-1 0 1 2 3 QUEUE_SIZE-1 array ,'*: : • ! ! ! " 2 ! A. 2. *!" 4. )" ! C: -" – + / ! ! ( ! # ), ." ! ." finish -1 ( N-1) /* QU_empty(): epistrefei TRUE/FALSE * analoga me to an i oura einai adeia */ int QU_empty(QUEUE q) { return q.finish==-1; } /* QU_full(): epistrefei TRUE/FALSE * analoga me to an i oura einai gemati */ int QU_full(QUEUE q) { return q.finish==QUEUE_SIZE-1; }
  3. 3. 5 A. 2. *!" 5. )" ! C: % " $ ! # finish+1 ( 2 ) /* QU_enqueue(): Eisagei to x stin oura q * epistrefei TRUE: se periptwsi epitixias * FALSE: se periptwsi apotixias */ int QU_enqueue(QUEUE *q,elem x) { if (QU_full(*q)) return FALSE; else { q->finish++; q->array[q->finish]=x; return TRUE; } } … finish=2 2 6 4 0 1 2 3 QUEUE_SIZE-1 array 0&1: ,'* (!. . ! «5»): … finish=3 2 6 4 0 1 2 3 QEUEUE_SIZE-1 array A. 2. *!" 6. )" ! C: *! % #$ ( ! # ) : 1. *! ! ( ! 2 ) 2. ! " ! 3. # finish ( # 1) … finish=2 2 6 4 0 1 2 3 QUEUE_SIZE-1 array 0&1: ,'*: …6 4 0 1 2 3 QUEUE_SIZE-1 array finish=1 *x=2 A. 2. *!" 6. )" ! C: *! % ## /* QU_dequeue(): Kanei apomakrinsi tou prwtou stoixeiou tis ouras * epistrefei TRUE: se periptwsi epitixias * FALSE: se periptwsi apotixias */ int QU_dequeue(QUEUE *q,elem *x) { int i; if (QU_empty(*q)) return FALSE; else { /* 1. Apothikeysi tou stoixeiou pou eksagetai*/ *x=q->array[0]; /* 2. Aristeri metakinisi twn stoixeiwn kata mia thesi */ for (i=0; i<q->finish; i++) q->array[i]=q->array[i+1]; /* 3. To finish meiwnetai kata 1 */ q->finish--; return TRUE; } } A. 2. *!" 7. )" ! C: # " " project queue.dev ! : ' queue.h ! ! " ' queue.c # ' main.c ! ! ! . « » ! # !" " . )! : • ' ! ! ! " «/"# C – 14: , . " ." # »
  4. 4. A. 3. + " 1. + " # ! ! ! , ! ! . ! ! . " . " "" ." ! ." ( ). / ! : enqueue(2) 2 enqueue(4) 2 4 4 dequeue( ) enqueue(5) 4 enqueue(3) 4 5 5 3 start=0 finish=0 start=0 finish=1 start=1 finish=1 start=1 finish=2 start=1 finish=3 start=-1 finish=-1 A. 3. + " 1. + " # / ! ( ) ! ." , ! 2 " ! ( ! ! ! ) , " ! 3! !" 2 " ! ! " ." ! ! " ( ! ! 1-1 0) 4 5 3 start=1 finish=3 0 1 2 3 array 4 5 6 7 0 array 1 2 34 5 6 7 start=1 finish=3 2 61 start=6finish=0 0 1 2 3 array 4 5 6 7 0 array 1 2 34 5 6 7start=6 finish=1 4 5 3 2 6 1 A. 3. + " 2. )" ! C: "# # & C " : • (struct) : • - QUEUE_SIZE • ." (start finish) ! " ( start=finish=-1 ). #define QUEUE_SIZE 10 /* Megethos pinaka ouras */ typedef int elem; /* typos dedomenwn ouras */ struct queue{ elem array[QUEUE_SIZE]; /* pinakas stoixeiwn */ int start; /* arxi tis ouras */ int finish; /* telos tis ouras */ }; typedef struct queue QUEUE; /* Sinwnimo tis ouras */ * ! : 0 array 1 2 34 5 6 7 start=1 finish=3 4 5 3 A. 3. + " 3. )" ! C: * ! # ! " -1 /* QU_init(): arxikopoiei tin oura */ void QU_init(QUEUE *q) { q->start =-1; q->finish=-1; } 0&1: ,'*: 0 array 1 2 34 5 6 7 QUEUE_SIZE=8 start=?? finish=?? 0 array 1 2 34 5 6 7 QUEUE_SIZE=8 start=-1 finish=-1
  5. 5. A. 3. + " 4. )" ! C: -" – + # ! ." ! ." start ( ." finish) -1 • * " ! ( 2 " ! . # ! ! ! ! . " ! ) /* QU_empty(): epistrefei TRUE/FALSE * analoga me to an i oura einai adeia */ int QU_empty(QUEUE q) { return q.finish==-1; } A. 3. + " 5. )" ! C: -" – / #! ! ! # ." ! ." finish 1 " ! ." start ( " start==finish+1) • ! ! ! finish=QUEUE_SIZE-1 ! ! " start==0 * ! ! 4 # : /* QU_full(): epistrefei TRUE/FALSE * analoga me to an i oura einai gemati */ int QU_full(QUEUE q) { return q.start==(q.finish+1)%QUEUE_SIZE; } )! : • " % ! 2 ! " ! # (/"# C – 4). • , # ! # " ! ! start ! , 0. A. 3. + " 6. )" ! C: % #" $ ( 2 ) : • ' finish ! ! ! : • ' finish+1 ( finish < QUEUE_SIZE-1) • ' 0 ( finish = QUEUE_SIZE-1) • ' ! finish. 0&1: 0 array 1 2 34 5 6 7 start=1 finish=3 4 5 3 0 array 1 2 34 5 6 7 start=1 4 5 35 finish=4 QUEUE_SIZE=8 QUEUE_SIZE=8 5 ,'* (!. . ! «5»): A. 3. + " 6. )" ! C: % $ /* QU_enqueue(): Eisagei to x stin oura q * epistrefei TRUE: se periptwsi epitixias * FALSE: se periptwsi apotixias */ int QU_enqueue(QUEUE *q,elem x) { if (QU_full(*q)) return FALSE; else { if (QU_empty(*q)) { q->start=0; q->finish=0; } else { q->finish=(q->finish+1)%QUEUE_SIZE; } q->array[q->finish]=x; return TRUE; } }
  6. 6. start=1 A. 3. + " 6. )" ! C: *! % # ( ! # ) ! ( 2 ): • *! start (# ! 2 ) : • * start < ! QUEUE_SIZE-1, start=start+1 • * start = QUEUE_SIZE-1 start=0 0&1: 0 array 1 2 34 5 6 7 start=1 finish=3 4 5 3 0 array 1 2 34 5 6 7 5 3 QUEUE_SIZE=8 QUEUE_SIZE=8 5 ,'* *x=4 finish=3 A. 3. + " 6. )" ! C: *! % /* QU_dequeue(): Kanei apomakrinsi tou prwtou stoixeiou tis ouras * epistrefei TRUE: se periptwsi epitixias * FALSE: se periptwsi apotixias */ int QU_dequeue(QUEUE *q,elem *x) { if (QU_empty(*q)) return FALSE; else { *x=q->array[q->start]; if (q->start == q->finish) /* H oura adeiase */ { q->start=-1; q->finish=-1; } else { q->start=(q->start+1)%QUEUE_SIZE; } return TRUE; } } A. 3. + " 7. )" ! C: " " project circular_queue.dev ! : ' queue.h ! ! " ' queue.c # ' main.c ! ! ! . « » ! # !" " . (. * ,2 1: ' ' ! $ + ! ! ! # " ! $ + ( ! ) . " # 80 . + ! " 5 ! " . % . " ! !# ! " . ' ! " ! ( ! ! " # ): 52 " . . $ ! !# ! " ! : * « » ! # , ! , "" # ! . * , ! " . * # " . ! " ! ! " ! 1 ! " . % !# !# ! ! ! . ' " . 2 , . % ! ! . $ ! ! " . )! : • " «! » ! , !" .
  7. 7. (. * ,2 2: ! , ! ! ! ! ! $ ! ( " , " ! ). - ! " ! « » : 1 ! ! $ ! . ( . ! ) + ! ! " ! , ! ! # "" " project ! " . )! : • " «! » ! , !" . (. * ,2 3: , ! % " ! . " ! H ! !# . ,! project ! " # # . ! ! " main, # ! . ! ! ,1 ! ! ! . " . )! : ! . ( ! !. . ! ) % ! , ! " ! , " . void QU_print(QUEUE *q) (. * ,2 4: * 2 ,! project 2 3, # $ ! "# : 2 ( ! # " , ! " , . .) % ! . ! void QU_reverse(QUEUE *q)

×