Fila Estática e Homogênea

23 

Full text

(1)

(VWUXWXUDGH'DGRV

Autoria: Carlos Eduardo Cayres | 4

o

semestre

Tema 04

Filas

7HPD

Filas

Autoria: Carlos Eduardo Cayres

Como citar esse documento:

CAYRES, Carlos Eduardo. Estrutura de Dados: Filas. Valinhos: Anhanguera Educacional, 2014.

Índice

‹ $QKDQJXHUD (GXFDFLRQDO 3URLELGD D UHSURGXomR ¿QDO RX SDUFLDO SRU TXDOTXHU PHLR GH LPSUHVVmR HP IRUPD LGrQWLFD UHVXPLGD RX PRGL¿FDGD HP OtQJXD SRUWXJXHVDRXTXDOTXHURXWURLGLRPD

Pág. 33

Pág. 34 Pág. 35

Pág. 34 Pág. 30 Pág. 28

ACOMPANHE

NA

WEB

Pág. 3

CONVITE

À

LEITURA

(2)

Filas

$¿ODpXPDestrutura de dadosFDSD]GHUHSUHVHQWDUFRQMXQWRVGHGDGRVRUJDQL]DGRVHPRUGHPOLQHDU4XDQGR VHXWLOL]DPYHWRUHVQDVUHSUHVHQWDo}HVGHVVDVHVWUXWXUDVVmRXVDGRVHQGHUHoRVFRQWtJXRVGHPHPyULDGRFRPSXWDGRU HDRUGHPOLQHDUTXHVmRLQGLFDGRVSHORVtQGLFHVGRVYHWRUHVFRQVLGHUDQGRVHTXHVXDLPSOHPHQWDomRHPDOJXPDV VLWXDo}HV SRGH H[LJLU PDLRU HVIRUoR FRPSXWDFLRQDO 7DLV UHSUHVHQWDo}HV GHQRPLQDPVH ¿ODV HVWiWLFDV (QWUHWDQWR TXDQGRDVHVWUXWXUDVGHGDGRVGRWLSR¿ODVmRUHSUHVHQWDGDVSRUHVWUXWXUDVTXHFRQWrPRGDGRHWDPEpPXPSRQWHLUR SDUDRSUy[LPRHOHPHQWRWrPVHHOHPHQWRVHQFDGHDGRVVHQGRSRUWDQWRGHQRPLQDGDV¿ODVGLQkPLFDV

(VWHWHPDDSUHVHQWDDHVWUXWXUDGHGDGRVGRWLSR¿ODXPDGDVHVWUXWXUDVGHSURJ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¿QLGR TXH QmR SRGHP VHU DOWHUDGDV GXUDQWH D H[HFXomR GR SURJUDPD PDQLSXODQGRVyXPWLSRGHGDGR1RFDVRGRH[HPSORDYDULiYHOpGRWLSRLQWHLUR¿OD

LQFOXGHLRVWUHDP! LQFOXGHVWGLRK! LQWPDLQ

{

LQW¿OD>@

(3)

LQWRSLM

L

GR

{

V\VWHP³&/6´ SULQWI³?Q?W0(18´ SULQWI³?Q,QVHULU´ SULQWI³?Q&RQVXOWDULQLFLR´ SULQWI³?Q&RQVXOWDU¿P´ SULQWI³?Q&RQVXOWDUWRGD¿OD´ SULQWI³?Q([FOXLU´

SULQWI³?Q(VYD]LDU´ SULQWI³?Q6DLU´

SULQWI³?Q'LJLWHVXDRSomR³ VFDQI³G´ RS

VZLWFKRS

{

FDVH

{

LIL

SULQWI³?Q)LODFKHLD?Q´

HOVH

{

SULQWI³?Q'LJLWHRQ~PHURDLQVHULU³ VFDQI³G´ ¿OD>L@

L

SULQWI³?Q1~PHURLQVHULGR?Q´

EUHDN

}

}

FDVH

{

LIL

SULQWI³?Q)LODYD]LD?Q´

HOVH

SULQWI³?Q,QLFLRGD¿ODG´¿OD>@

EUHDN

}

FDVH

{

LIL

SULQWI³?Q)LODYD]LD?Q´ HOVH

SULQWI³?Q)LPGD¿ODG´¿OD>L@ EUHDN

}

FDVH

{

LIL

SULQWI³?Q)LODYD]LD?Q´

HOVH

{

SULQWI³?Q7RGDD¿OD³

IRUM MLM

SULQWI³G³¿OD>M@

}

EUHDN

}

(4)

FDVH

{

LIL

SULQWI³?Q)LODYD]LD?Q´ HOVH

{

IRUM MLM

¿OD>M@ ¿OD>M@

SULQWI³?Q1~PHURH[FOXtGR?Q´

L

}

EUHDN

}

FDVH

{

LIL

SULQWI³?Q)LODYD]LD?Q´

HOVH

{

L

SULQWI³?Q)LODHVYD]LDGD´

}

EUHDN

}

GHIDXOW

{

LIRS

SULQWI³?Q2SomRLQYiOLGD?Q´

}

}

V\VWHP³3$86(´

}

ZKLOHRS

}

Fila Estática e Heterogênea

6mR HVWUXWXUDV FRP WDPDQKR SUpGH¿QLGR TXH QmR SRGHP VRIUHU DOWHUDomR GXUDQWH D H[HFXomR GR SURJUDPD PDQLSXODQGRPDLVGHXPWLSRGHGDGR1RFDVRGRH[HPSORDVYDULiYHLVVmRGRWLSRLQWHLURcodigoHGRWLSRUHDOnota

LQFOXGHLRVWUHDP! LQFOXGHVWGLRK! LQWPDLQ

{

VWUXFW

{

LQWFRGLJR ÀRDWQRWD `¿OD>@ LQWRSLM L GR

{

V\VWHP³&/6´ SULQWI³?Q?W0(18´ SULQWI³?Q,QVHULU´ SULQWI³?Q&RQVXOWDULQLFLR´ SULQWI³?Q&RQVXOWDU¿P´ SULQWI³?Q&RQVXOWDUWRGD¿OD´ SULQWI³?Q([FOXLU´

(5)

SULQWI³?Q(VYD]LDU´

SULQWI³?Q6DLU´

SULQWI³?Q'LJLWHVXDRSomR³ VFDQI³G´ RS

VZLWFKRS

{

FDVH

{

LIL

SULQWI³?Q)LODFKHLD?Q´

HOVH

{

SULQWI³?Q'LJLWHRFyGLJRGRDOXQR³ VFDQI³G´ ¿OD>L@FRGLJR SULQWI³?Q'LJLWHDQRWDGRDOXQR³ VFDQI³I´ ¿OD>L@QRWD

L

SULQWI³?Q'DGRVLQVHULGRV?Q´

EUHDN

} }

FDVH

{

LIL

SULQWI³?Q)LODYD]LD?Q´ HOVH

{

SULQWI³?Q,QLFLRGD¿OD?Q´

SULQWI³?Q&yGLJRG´¿OD>@FRGLJR

SULQWI³?Q1RWDI?Q´¿OD>@QRWD

}

EUHDN

}

FDVH

{

LIL

SULQWI³?Q)LODYD]LD?Q´ HOVH

{

SULQWI³?Q)LPGD¿OD?Q´

SULQWI³?Q&yGLJRG´¿OD>L@FRGLJR SULQWI³?Q1RWDI?Q´¿OD>L@QRWD

}

EUHDN

}

FDVH

{

LIL

SULQWI³?Q)LODYD]LD?Q´ HOVH

{

SULQWI³?Q7RGDD¿OD?Q´

IRUM MLM

{

SULQWI³?Q&yGLJRG´¿OD>M@FRGLJR SULQWI³?Q1RWDI?Q´¿OD>M@QRWD

}

}

(6)

EUHDN

}

FDVH

{

LIL

SULQWI³?Q)LODYD]LD?Q´

HOVH

{

IRUM MLM

{

¿OD>M@FRGLJR ¿OD>M@FRGLJR ¿OD>M@QRWD ¿OD>M@QRWD

}

SULQWI³?Q'DGRVH[FOXLGRV?Q´

L

}

EUHDN

}

FDVH

{

LIL

SULQWI³?Q)LODYD]LD?Q´ HOVH

{

L

SULQWI³?Q)LODHVYD]LDGD?Q´

}

EUHDN

}

GHIDXOW

{

LIRS

SULQWI³?Q2SomRLQYiOLGD?Q´

} }

V\VWHP³3$86(´

}

ZKLOHRS

}

Fila Dinâmica e Homogênea

6mR HVWUXWXUDV TXH XWLOL]DP SRQWHLURV SDUD LQGH[DU HQGHUHoRV GH YDULiYHLV SHUPLWLQGR D LQVHUomR GLQkPLFD GH GDGRVGXUDQWHDH[HFXomRGRSURJUDPDHPDQLSXODQGRDSHQDVXPWLSRGHGDGR1RFDVRGRH[HPSORDYDULiYHOpGR WLSRLQWHLUR¿OD

LQFOXGHLRVWUHDP! LQFOXGHVWGLRK! LQWPDLQ

{

VWUXFW¿OD

{

LQWQXP ¿ODSUR[ `

¿ODLQLFLR¿PDX[ LQWRS

LQLFLR 18// GR

{

V\VWHP³&/6´

(7)

SULQWI³?Q?W0(18´

SULQWI³?Q,QVHULU´ SULQWI³?Q&RQVXOWDULQLFLR´ SULQWI³?Q&RQVXOWDU¿P´ SULQWI³?Q&RQVXOWDUWRGD¿OD´ SULQWI³?Q([FOXLU´

SULQWI³?Q(VYD]LDU´ SULQWI³?Q6DLU´

SULQWI³?Q'LJLWHVXDRSomR³ VFDQI³G´ RS

VZLWFKRS

{

FDVH

{

DX[ QHZ¿OD

SULQWI³?Q'LJLWHRQ~PHURDLQVHULU³

VFDQI³G´ DX[!QXP

LILQLFLR 18//

LQLFLR DX[

HOVH

¿P!SUR[ DX[

¿P DX[

¿P!SUR[ 18//

SULQWI³?Q1~PHURLQVHULGR?Q´

EUHDN

}

FDVH

{

LILQLFLR 18//

SULQWI³?Q)LODYD]LD?Q´

HOVH

SULQWI³?Q1~PHURLQLFLDOG?Q´LQLFLR!QXP

EUHDN

}

FDVH

{

LILQLFLR 18//

SULQWI³?Q)LODYDL]LD?Q´

HOVH

SULQWI³?Q1~PHUR¿QDOG?Q´¿P!QXP

EUHDN

}

FDVH

{

LILQLFLR 18//

SULQWI³?Q)LODYD]LD?Q´

HOVH

{

SULQWI³?Q7RGDD¿OD³

DX[ LQLFLR

ZKLOHDX[ 18//

{

SULQWI³G³DX[!QXP

DX[ DX[!SUR[

} }

EUHDN

}

(8)

FDVH

{

LILQLFLR 18//

SULQWI³?Q)LODYD]LD?Q´

HOVH

{

DX[ LQLFLR

LQLFLR LQLFLR!SUR[

GHOHWHDX[

SULQWI³?Q1~PHURH[FOXLGR?Q´

}

EUHDN

}

FDVH

{

LILQLFLR 18//

SULQWI³?Q)LODYD]LD?Q´

HOVH

{

DX[ LQLFLR

ZKLOHDX[ 18//

{

LQLFLR LQLFLR!SUR[

GHOHWHDX[

DX[ LQLFLR

}

SULQWI³?Q)LODHVYD]LDGD?Q´

}

EUHDN

}

GHIDXOW

{

LIRS

SULQWI³?Q2SomRLQYDOLGD?Q´

} }

V\VWHP³3$86(´

}

ZKLOHRS

}

Fila Dinâmica e Heterogênea

6mRHVWUXWXUDVTXHXWLOL]DPSRQWHLURVSDUDLQGH[DUHQGHUHoRVGHYDULiYHLVSHUPLWLQGRDLQVHUomRGLQkPLFDGHGDGRV GXUDQWHDH[HFXomRGRSURJUDPDHPDQLSXODQGRPDLVGHXPWLSRGHGDGR1RFDVRGRH[HPSORDVYDULiYHLVVmRGRWLSR LQWHLURcodigoHGRWLSRUHDOsalario

LQFOXGHLRVWUHDP! LQFOXGHVWGLRK! LQWPDLQ

{

VWUXFW¿OD

{

LQWFRGLJR ÀRDWVDODULR ¿ODSUR[ `

¿ODLQLFLR¿PDX[ LQWRS

LQLFLR 18// GR

(9)

{

V\VWHP³&/6´ SULQWI³?Q?W0(18´ SULQWI³?Q,QVHULUGDGRV´

SULQWI³?Q&RQVXOWDUGDGRVGRLQLFLR´ SULQWI³?Q&RQVXOWDUGDGRVGR¿P´ SULQWI³?Q&RQVXOWDUWRGD¿OD´ SULQWI³?Q([FOXLUGDGRV´ SULQWI³?Q(VYD]LDU¿OD´ SULQWI³?Q6DLU´

SULQWI³?Q'LJLWHVXDRSÁDR³ VFDQI³G´ RS

VZLWFKRS

{

FDVH

{

DX[ QHZ¿OD

SULQWI³?Q'LJLWHRFyGLJRGRIXQFLRQDULR³ VFDQI³G´ DX[!FRGLJR

SULQWI³?Q'LJLWHRVDODULR³ VFDQI³I´ DX[!VDODULR LILQLFLR 18//

LQLFLR DX[

HOVH

¿P!SUR[ DX[

¿P DX[

¿P!SUR[ 18//

SULQWI³?Q'DGRVLQVHULGRV?Q´

EUHDN

}

FDVH

{

LILQLFLR 18//

SULQWI³?Q)LODYD]LD?Q´

HOVH

{

SULQWI³?Q'DGRVLQLFLDLV?Q´ SULQWI³?Q&yGLJRG´LQLFLR!FRGLJR SULQWI³?Q6DODULRI?Q´LQLFLR!VDODULR

}

EUHDN

}

FDVH

{

LILQLFLR 18//

SULQWI³?Q)LODYD]LD?Q´

HOVH

{

SULQWI³?Q'DGRV¿QDLV?Q´

SULQWI³?Q&yGLJRG´¿P!FRGLJR

SULQWI³?Q6DODULRI?Q´¿P!VDODULR

}

EUHDN

}

FDVH

{

LILQLFLR 18//

(10)

SULQWI³?Q)LODYD]LD?Q´

HOVH

{

SULQWI³?Q7RGDD¿OD?Q´

DX[ LQLFLR

ZKLOHDX[ 18//

{

SULQWI³?Q&yGLJRG´DX[!FRGLJR

SULQWI³?Q6DODULRI?Q´DX[!VDODULR DX[ DX[!SUR[

} }

EUHDN

}

FDVH

{

LILQLFLR 18//

SULQWI³?Q)LODYD]LD?Q´

HOVH

{

DX[ LQLFLR

LQLFLR LQLFLR!SUR[

GHOHWHDX[

SULQWI³?Q'DGRVH[FOXLGRV?Q´

}

EUHDN

}

FDVH

{

LILQLFLR 18//

SULQWI³?Q)LODYD]LD?Q´

HOVH

{

DX[ LQLFLR

ZKLOHDX[ 18//

{

LQLFLR LQLFLR!SUR[

GHOHWHDX[

DX[ LQLFLR

}

SULQWI³?Q)LODHVYD]LDGD?Q´

}

EUHDN

}

GHIDXOW

{

LIRS

SULQWI³?Q2SokRLQYiOLGD?Q´

} }

V\VWHP³3$86(´

}

ZKLOHRS

}

(11)

Exemplo de Fila e Pilha Dinâmica Heterogênea no Mesmo Programa LQFOXGHLRVWUHDP!

LQFOXGHVWGLRK! LQWPDLQ

{

&ULDQGRDHVWUXWXUDGD¿ODGHGHSHQGHQWHV VWUXFWGHSHQGHQWH

{

FKDUQRPHBGHS>@ GHSHQGHQWHSUR[BGHS

`

&ULDQGRDHVWUXWXUDGDSLOKDGHIXQFLRQiULRV VWUXFWIXQFLRQDULR

{

LQWQXP

FKDUQRPHBIXQF>@ ÀRDWYDORUTWGH GHSHQGHQWHGHS IXQFLRQDULRSUR[BIXQF

`

IXQFLRQDULRWRSRBIXQFDX[BIXQF GHSHQGHQWHDX[BGHS¿PBGHS WRSRBIXQF 18//

LQWRSQXPHURQIDFKRXVRPD ÀRDWVDOBEUXWRVDODULRWRWDO

QXPHUR YDULiYHOXWLOL]DGDSDUDJHUDURQ~PHURGRIXQFLRQiULR

GR

{

V\VWHP³&/6´ SULQWI³0HQX´

SULQWI³?Q&DGDVWUDUIXQFLRQiULR´ SULQWI³?Q&DGDVWUDUGHSHQGHQWH´ SULQWI³?Q&RQVXOWDUVDOiULR´

SULQWI³?Q&RQVXOWDUIROKDGHSDJDPHQWR´ SULQWI³?Q([FOXLUGHSHQGHQWH´

SULQWI³?Q([FOXLUIXQFLRQiULR´ SULQWI³?Q6DLU´

SULQWI³?Q'LJLWHVXDRSomR³

VFDQI³G´ RS

LIRS__RS!

SULQWI³?Q2SomRLQYiOLGD?Q´

LIRS

{

DX[BIXQF QHZIXQFLRQDULR QXPHUR QXPHUR DX[BIXQF!QXP QXPHUR

SULQWI³?Q'LJLWHRQRPHGRIXQFLRQiULR³ VFDQI³V´ DX[BIXQF!QRPHBIXQF

SULQWI³?Q'LJLWHDTXDQWLGDGHGHKRUDVWUDEDOKDGDV³ VFDQI³I´ DX[BIXQF!TWGH

SULQWI³?Q'LJLWHRYDORUGDKRUDWUDEDOKDGD³ VFDQI³I´ DX[BIXQF!YDORU

DX[BIXQF!GHS 18//

(12)

DX[BIXQF!SUR[BIXQF WRSRBIXQF

WRSRBIXQF DX[BIXQF

SULQWI³?Q)XQFLRQiULRFDGDVWUDGR?Q´

}

LIRS

{

LIWRSRBIXQF 18//

SULQWI³?Q3LOKDGHIXQFLRQiULRVYD]LD?Q´

HOVH

{

SULQWI³?Q'LJLWHRQ~PHURGRIXQFLRQiULRTXHUHFHEHURGHSHQGHQWH³ VFDQI³G´ QI

DFKRX

DX[BIXQF WRSRBIXQF

ZKLOHDX[BIXQF 18// DFKRX

{

LIDX[BIXQF!QXP QI

DFKRX

HOVH

DX[BIXQF DX[BIXQF!SUR[BIXQF

}

LIDFKRX

SULQWI³?Q1mRH[LVWHIXQFLRQiULRFDGDVWUDGRFRPRQ~PHURG?Q´QI

HOVH {

DX[BGHS QHZGHSHQGHQWH

SULQWI³?Q'LJLWHRQRPHGRGHSHQGHQWH³

VFDQI³V´ DX[BGHS!QRPHBGHS

LIDX[BIXQF!GHS 18//

DX[BIXQF!GHS DX[BGHS

HOVH

{

¿PBGHS DX[BIXQF!GHS

ZKLOH¿PBGHS!SUR[BGHS 18//

{

¿PBGHS ¿PBGHS!SUR[BGHS

}

¿PBGHS!SUR[BGHS DX[BGHS

}

DX[BGHS!SUR[BGHS 18//

SULQWI³?Q'HSHQWHQGHFDGDVWUDGRFRPVXFHVVR?Q´ }

} }

LIRS

{

LIWRSRBIXQF 18//

SULQWI³?Q3LOKDGHIXQFLRQiULRVYD]LD?Q´

HOVH

{

SULQWI³?Q'LJLWHRQ~PHURGRIXQFLRQiULRSDUDFRQVXOWDURVDOiULR³ VFDQI³G´ QI

DFKRX

DX[BIXQF WRSRBIXQF

ZKLOHDX[BIXQF 18// DFKRX

{

LIDX[BIXQF!QXP QI

DFKRX

(13)

HOVH

DX[BIXQF DX[BIXQF!SUR[BIXQF

}

LIDFKRX

SULQWI³?Q1mRH[LVWHIXQFLRQiULRFDGDVWUDGRFRPRQ~PHURG?Q´QI HOVH

{

VDOBEUXWR DX[BIXQF!TWGHDX[BIXQF!YDORU

VRPD

¿PBGHS DX[BIXQF!GHS ZKLOH¿PBGHS 18//

{

VRPD VRPD

¿PBGHS ¿PBGHS!SUR[BGHS

}

VDODULR VDOBEUXWRVRPD

SULQWI³?Q6DOiULRGRIXQFLRQiULR I?Q´VDODULR

} } }

LIRS

{

LIWRSRBIXQF 18//

SULQWI³?Q3LOKDGHIXQFLRQiULRVYD]LD?Q´ HOVH

{

WRWDO

DX[BIXQF WRSRBIXQF ZKLOHDX[BIXQF 18//

{

VDOBEUXWR DX[BIXQF!TWGHDX[BIXQF!YDORU

VRPD

¿PBGHS DX[BIXQF!GHS ZKLOH¿PBGHS 18//

{

VRPD VRPD

¿PBGHS ¿PBGHS!SUR[BGHS

}

VDODULR VDOBEUXWRVRPD WRWDO WRWDOVDODULR

DX[BIXQF DX[BIXQF!SUR[BIXQF

}

SULQWI³?Q7RWDOGDIROKDGHSDJDPHQWR I?Q´WRWDO

} }

LIRS

{

LIWRSRBIXQF 18//

SULQWI³?Q3LOKDGHIXQFLRQiULRVYD]LD?Q´

HOVH

{

SULQWI³?Q'LJLWHRQ~PHURGRIXQFLRQiULRGRTXDORGHSHQGHQWHVHUH[FOXtGR³

VFDQI³G´ QI

DFKRX

DX[BIXQF WRSRBIXQF

ZKLOHDX[BIXQF 18// DFKRX

{

LIDX[BIXQF!QXP QI

(14)

DFKRX

HOVH

DX[BIXQF DX[BIXQF!SUR[BIXQF

}

LIDFKRX

SULQWI³?Q1mRH[LVWHIXQFLRQiULRFDGDVWUDGRFRPRQ~PHURG?Q´QI

HOVH {

LIDX[BIXQF!GHS 18//

SULQWI³?Q(VWHIXQFLRQiULRQmRWHPGHSHQGHQWHVSDUDH[FOXVmR?Q´ HOVH

{

DX[BGHS DX[BIXQF!GHS

DX[BIXQF!GHS DX[BGHS!SUR[BGHS

GHOHWHDX[BGHS

SULQWI³?Q'HSHQGHQWHH[FOXtGRFRPVXFHVVR?Q´

} }

} }

LIRS

{

LIWRSRBIXQF 18//

SULQWI³?Q3LOKDGHIXQFLRQiULRVYD]LD?Q´

HOVH

{

DX[BIXQF WRSRBIXQF DX[BGHS DX[BIXQF!GHS

ZKLOHDX[BGHS 18//

{

DX[BIXQF!GHS DX[BGHS!SUR[BGHS

GHOHWHDX[BGHS

DX[BGHS DX[BIXQF!GHS

}

WRSRBIXQF WRSRBIXQF!SUR[BIXQF GHOHWHDX[BIXQF

SULQWI³?Q)XQFLRQiULRHVHXVGHSHQGHQWHVH[FOXtGRVFRPVXFHVVR?Q´

} }

V\VWHP³3$86(´ `ZKLOHRS

}

POR

DENTRO

DO

TEMA

Aula sobre Fila Estática e Dinâmica em JAVA (texto)

2TXHGLIHUHQFLDD¿ODGDSLOKDpDRUGHPGHVDtGDGRVHOHPHQWRVHQTXDQWRQDSLOKD³R~OWLPR

TXHHQWUDpRSULPHLURTXHVDL´QD¿OD³RSULPHLURTXHHQWUDpRSULPHLURTXHVDL´DVLJOD),)2±

¿UVWLQ¿UVWRXW±pXVDGDSDUDGHVFUHYHUHVVDHVWUDWpJLD

'LVSRQtYHOHPKWWSZZZPDQIUHGFRPEULQGH[SKSEVLHVWUXWXUDGHGDGRVLDXODILODHVWDWLFDHGL QDPLFDHPMDYD!$FHVVRHPDJR

}

(15)

Estruturas de Dados em Java Pilha e Fila (apresentação)

• $LGHLDIXQGDPHQWDOGD¿ODpTXHVySRGHPRVLQVHULUXPQRYRHOHPHQWRQR¿QDOGD¿ODHVy

SRGHPRV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HQVVHJXLQWHV

• &DGDVWUDUIXQFLRQiULRVQD¿OD

• 0RVWUDURLPSRVWRHRVDOiULRGHWRGRVRVIXQFLRQiULRVGD¿OD

• 0RVWUDURVIXQFLRQiULRVFXMRQRPHFRPHFHFRPXPDOHWUDGLJLWDGD • (VYD]LDUD¿ODDQWHVGHVDLUGRSURJUDPD

(17)

Questão 5

&RPEDVHQDHVWUXWXUDGHSURJUDPDomRGDOLQJXDJHP&FULHXPSURJUDPDTXHFDUUHJXHXPD¿ODGLQkPLFDSDUDPDQLSXODUXPD HVWUXWXUDFRQWHQGRRQRPHHDPpGLDGHDOXQRV5HVROYDRVLWHQVDVHJXLU

• &DGDVWUDUDOXQR

• 0RVWUDURQRPHHDPpGLDGRVDSURYDGRV • 0RVWUDURQRPHHDPpGLDGRVUHSURYDGRV

• (VYD]LDUD¿ODDQWHVGHVDLUGRSURJUDPD

Obs.pFRQVLGHUDGRDSURYDGRRDOXQRFRPPpGLD!

2VFRQFHLWRVHH[HPSORVSUiWLFRVHP&DSUHVHQWDGRVQHVWHWHPDGHL[DUDPEHPFODURTXHDHVWUXWXUDGHGDGRVGR WLSR¿ODpPXLWRYHUViWLOQDVROXomRGHSUREOHPDGRFRWLGLDQR6XDHVWUXWXUDSHUPLWHDUPD]HQDUWLSRVGHGDGRVYDULDGRV SRVVLELOLWDQGRRWUDEDOKRFRPHVWUXWXUDVKRPRJrQHDVHKHWHURJrQHDV

$VRSHUDo}HVEiVLFDVGHLQVHUomRFRQVXOWDUHPRomRHHVYD]LDPHQWRGD¿ODIRUDPEHPH[SORUDGDVQRVH[HPSORVH H[HUFtFLRVSURSRVWRVEHPFRPRDVHVWUXWXUDVGH¿ODHVWiWLFDGLQkPLFDKRPRJrQHDHKHWHURJrQHDFRPH[HPSORVHP &SDUDFDGDXPDGDVHVWUXWXUDV

Obs.pFRQVLGHUDGRDSURYDGRRDOXQRFRPPpGLD

2 L O i L & G G L E O G G G G

FINALIZANDO

$=(9('2*LOEHUW(VWUX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HPHQWRVGLIHUHQWHVGHVLJXDLV %RRNV

E t t d d d W m W W G G G p I t¿ G L m W G

(18)

Questão 1

Resposta:

LQFOXGHLRVWUHDP! LQFOXGHVWGLRK! LQWPDLQ

{

VWUXFWSLOKD

{

LQWQXP

SLOKDSUR[

`

SLOKDWRSRDX[

LQWRS

WRSR 18//

GR

{

V\VWHP³&/6´

SULQWI³?Q0(18´

SULQWI³?Q,QVHULU´

SULQWI³?Q&RQVXOWDUSLOKD´ SULQWI³?Q([FOXLUQ~PHURGDSLOKD´

SULQWI³?Q6DLU´

SULQWI³?Q'LJLWHVXDRSomR³

VFDQI³G´ RS

LIRS__RS!

SULQWI³?Q2SomRLQYiOLGD?Q´

GABARITO

LIRS

{

DX[ QHZSLOKD

SULQWI³?Q'LJLWHRQ~PHUR³

VFDQI³G´ DX[!QXP

DX[!SUR[ WRSR

WRSR DX[

SULQWI³?Q1~PHURLQVHULGR?Q´

}

LIRS

{

LIWRSR 18//

SULQWI³?Q3LOKDYD]LD?Q´

HOVH

{

DX[ WRSR

SULQWI³?Q7RGDDSLOKD³

ZKLOHDX[ 18//

{

SULQWI³G³DX[!QXP

DX[ DX[!SUR[

}

} }

LIRS

{

LIWRSR 18//

SULQWI³?Q3LOKDYD]LD?Q´

HOVH

(19)

DX[ WRSR

WRSR WRSR!SUR[

GHOHWHDX[

SULQWI³?Q1~PHURGRWRSRH[FOXLGR?Q´

} }

V\VWHP³3$86(´

}

ZKLOHRS

}

&OLTXHDTXLSDUDYROWDUjVHomR$JRUDpD6XD9H]

Questão 2

Resposta: $OWHUQDWLYD&

$OLQKDVGHFRPDQGR¿OD>@HWRSRPRVWUDPFODUDPHQWHXPDHVWUXWXUDGHDORFDomRHVWiWLFDQRWUHFKRGHFyGLJRGD TXHVWmR$¿ODMipGH¿QLGDFRPRXPYHWRUGHSRVLo}HVHDFDGDLQVHUomRDYDULiYHOWRSRpLQFUHPHQWDGDGHHP

Questão 3

Resposta: $OWHUQDWLYD'

1DVOLQKDVGHFRPDQGR

struct {

int codigo; ÀRDWVDO `¿OD>@

'H¿QHVHXPDHVWUXWXUDFRPXPGDGRGRWLSRLQWHLURHRXWURGRWLSRUHDOFDUDFWHUL]DQGRXPDHVWUXWXUDKHWHURJrQHD

Questão 4

Resposta:

LQFOXGHLRVWUHDP! LQFOXGHVWGLRK! LQFOXGHFW\SHK!

LQWPDLQ

{

VWUXFWIXQFLRQDULR

{

FKDUQRPH>@

ÀRDWVDO

IXQFLRQDULRSUR[

`

IXQFLRQDULRLQLFLR¿PDX[

ÀRDWLPSRVWRUHFHEHU

LQLFLR 18//

LQWDFKRXL FKDUOHWUD

V\VWHP³&/6´

&DGDVWUDQGRIXQFLRQiULRVQD)LOD

IRUL LL

{

DX[ QHZIXQFLRQDULR

(20)

SULQWI³'LJLWHRQRPHGRIXQFLRQiULR³

VFDQI³V´ DX[!QRPH SULQWI³'LJLWHRVDOiULR³ VFDQI³I´ DX[!VDO

LILQLFLR 18//

LQLFLR DX[

HOVH

¿P!SUR[ DX[

¿P DX[

¿P!SUR[ 18//

}

PRVWUDQGRRLPSRVWRHRVDOiULRGHWRGRVRVIXQFLRQiULRVGD¿OD V\VWHP³&/6´

DX[ LQLFLR ZKLOHDX[ 18//

{

SULQWI³?Q1RPHGRIXQFLRQiULRV´DX[!QRPH

LIDX[!VDO

LPSRVWR

HOVHLIDX[!VDO

LPSRVWR DX[!VDO

HOVH

LPSRVWR DX[!VDO

SULQWI³?Q9DORUGRLPSRVWR5I´LPSRVWR

UHFHEHU DX[!VDOLPSRVWR

SULQWI³?Q9DORUDUHFHEHU5I?Q´UHFHEHU

DX[ DX[!SUR[

}

V\VWHP³3$86(´ V\VWHP³&/6´

0RVWUDQGRRVIXQFLRQiULRVFXMRQRPHFRPHFHFRPXPDOHWUDGLJLWDGD SULQWI³?Q?Q'LJLWHXPDOHWUD³

VFDQI³V´ OHWUD

DFKRX

DX[ LQLFLR ZKLOHDX[ 18//

{

LIDX[!QRPH>@ WRORZHUOHWUD __DX[!QRPH>@ WRXSSHUOHWUD

{

SULQWI³?Q1RPHGRIXQFLRQDULRV´DX[!QRPH UHFHEHU DX[!VDOLPSRVWR

SULQWI³?Q9DORUDUHFHEHU5I?Q´UHFHEHU

DFKRX

}

DX[ DX[!SUR[

}

(21)

LIDFKRX

{

SULQWI³?Q?Q1HQKXPIXQFLRQiULRHQFRQWUDGR?Q´ V\VWHP³3$86(´

}

HOVH

{

V\VWHP³3$86(´ V\VWHP³&/6´

}

(VYD]LDQGRD¿ODDQWHVGHVDLUGRSURJUDPD DX[ LQLFLR

ZKLOHDX[ 18//

{

LQLFLR LQLFLR!SUR[

GHOHWHDX[

DX[ LQLFLR

}

V\VWHP³&/6´

SULQWI³?Q?Q?Q)LODHVYD]LDGDFRPVXFHVVR?Q´ V\VWHP³3$86(´

}

&OLTXHDTXLSDUDYROWDUjVHomR$JRUDpD6XD9H]

Questão 5

Resposta:

LQFOXGHLRVWUHDP! LQFOXGHVWGLRK! LQFOXGHFW\SHK!

LQWPDLQ

{

VWUXFWDOXQR

{

FKDUQRPH>@

ÀRDWPHGLD

DOXQRSUR[

`

DOXQRLQLFLR¿PDX[

LQLFLR 18//

LQWL

V\VWHP³&/6´

IRUL LL

{

DX[ QHZDOXQR

SULQWI³'LJLWHRQRPHGRDOXQR³ VFDQI³V´ DX[!QRPH SULQWI³'LJLWHDPpGLD³ VFDQI³I´ DX[!PHGLD

(22)

LILQLFLR 18//

LQLFLR DX[

HOVH

¿P!SUR[ DX[

¿P DX[

¿P!SUR[ 18//

}

V\VWHP³&/6´

SULQWI³?Q/LVWDGHDSURYDGRV´ DX[ LQLFLR

ZKLOHDX[ 18//

{

LIDX[!PHGLD!

{

SULQWI³?Q1RPHV´DX[!QRPH SULQWI³?QPpGLDI?Q´DX[!PHGLD

}

DX[ DX[!SUR[

}

SULQWI³?Q?Q/LVWDGHUHSURYDGRV´ DX[ LQLFLR

ZKLOHDX[ 18//

{

LIDX[!PHGLD

{

SULQWI³?Q1RPHV´DX[!QRPH

SULQWI³?QPpGLDI?Q´DX[!PHGLD

}

DX[ DX[!SUR[

}

V\VWHP³3$86(´ DX[ LQLFLR ZKLOHDX[ 18//

{

LQLFLR LQLFLR!SUR[

GHOHWHDX[

DX[ LQLFLR

} }

&OLTXHDTXLSDUDYROWDUjVHomR$JRUDpD6XD9H]

(23)

Figure

Updating...

References

Updating...

Download now (23 pages)