SlideShare uma empresa Scribd logo
1 de 23
Baixar para ler offline
Tecnologia em Análise e
Desenvolvimento de Sistemas
Estruturas de dados I
ED1A2 - FILA
FILA
● Análogo a uma fila de banco
● Sempre o primeiro da fila é atendido
● Quando alguém chega vai para o final da fila
● FIFO (First In First Out), ou seja, o primeiro elemento que entra é o
primeiro a sair.
FILA
• As inserções são feitas sempre no FINAL
• As retiradas são feitas sempre do INÍCIO
FILA–OPERAÇÕES BÁSICAS
• Duas operações básicas:
– INSERIR (PUT/ENQUEUE): Operação utilizada para
inserir um novo elemento NO FINAL DA FILA.
– REMOVER (GET/DEQUEUE): Operação utilizada para
remover o elemento DO INÍCIO DA FILA.
Barbosa
e Silva
2010
FILA–APONTAMENTO
• Implementação NÃO SEQUENCIAL e
DINÂMICA, ou seja:
• Os elementos não estão necessariamente
ordenados na memória
• Não existe um limite máximo de tamanho
previamente definido como na implementação
através de arranjos!
5
Barbosa
e Silva
2010
FILA–APONTAMENTO
• Cada célula contém o VALOR propriamente dito e um apontador que
aponta para o próximo item da fila.
• Existe uma célula que aponta para o primeiro e outra para o último.
• Quando a fila está vazia, primeiro e último apontam para null.
6
Barbosa
e Silva
2010
Modelagem
FILA–INSERIR
• A operação INSERIR é dividida em 5 etapas:
– Criação de um novo nó para receber o valor inserido
– O novo elemento passa a apontar para null
– Verifica se a pilha está vazia
• primeiro e último elemento aponta para novo
– O último elemento passa a apontar para o novo elemento
– o último elemento passa a ser o novo
– Incrementa-se o tamanho da fila
Barbosa
e Silva
2010
FILA–INSERIR
• Inserir o elemento 3 na pilha:
• PASSO 1: Criando um novo nó
• Novo aponta para NULL
9
Cont = 3
Barbosa
e Silva
2010
• PASSO 2: O último elemento passa a
apontar para o novo elemento
10
FILA–INSERIR
Cont = 3
• PASSO 3: O último elemento passa a ser o
novo
FILA – INSERIR
Cont = 3
• PASSO 5: Incrementar o contador
FILA – INSERIR
Cont = 4
13
FILA – INSERIR (IMPLEMENTAÇÃO)
FILA – REMOVER
• A operação REMOVER é dividida em 4 etapas:
– Verificar se a fila está vazia
– Verificar se contém apenas um elemento
– O primeiro elemento passa a ser o elemento
que era apontado pelo primeiro (seguinte)
– Decrementar o tamanho da pilha
14
• PASSO 1: Verificar se a pilha está vazia
• PASSO 2: Se não estiver vazia, verificar se
existe apenas um elemento. Nesse caso, o
apontador último passa a apontar para null
15
FILA – REMOVER
ultimo = null
• PASSO 3: Atualizar o ponteiro de primeiro (o
primeiro elemento passa a ser o elemento que
era apontado pelo primeiro (próximo))
01/11/2017 Filas (Implementação utilizando Ponteiros)
FILA – REMOVER
Cont = 4
• PASSO 4: Decrementar o tamanho da fila
01/11/2017 Filas (Implementação utilizando Ponteiros) 17
FILA – REMOVER
Cont = 3
Filas (Implementação utilizando Ponteiros)
FILA – REMOVER (IMPLEMENTAÇÃO)
01/11/2017 Filas (Implementação utilizando Ponteiros) 19
FILA – IMPRIMIR (IMPLEMENTAÇÃO)
FAÇA AS DEMAIS OPERAÇÕES COM FILA
• Verifica se a fila está vazia
• Verifica se a fila está cheia
• Exibe o elemento do início
• Exibe o elemento do fim
20
Material de apoio
Estudem também
http://www.each.usp.br/digiampietri/ed/aula12.pdf
Exercício Sala
1) Crie uma estrutura de fila que faça apenas as operações de
ENQUEUE, DEQUEUE e EXIBIR elementos do tipo int. Utilize apenas
estruturas dinâmicas
2) Altere o exercício anterior de modo a realizar as demais operações.:
Verifica se a fila está vazia
Verifica se a fila está cheia
Exibe o elemento do início
Exibe o elemento do fim
Exercício (extra)
1. Crie uma estrutura que faça apenas as operações de inserir, remover e
exibir. Cada posição deve armazenar uma operação do tipo string
referenciando o movimento de um jogo de xadrez. Por exemplo Be5
(bispo se move para e5), Cf3 (cavalo se move para f3). A alocação deve ser
dinâmina.
2. Altere o exercício anterior de modo a realizar as demais operações.

Mais conteúdo relacionado

Último

ATIVIDADE 1 - CUSTOS DE PRODUÇÃO - 52_2024.docx
ATIVIDADE 1 - CUSTOS DE PRODUÇÃO - 52_2024.docxATIVIDADE 1 - CUSTOS DE PRODUÇÃO - 52_2024.docx
ATIVIDADE 1 - CUSTOS DE PRODUÇÃO - 52_2024.docx2m Assessoria
 
ATIVIDADE 1 - LOGÍSTICA EMPRESARIAL - 52_2024.docx
ATIVIDADE 1 - LOGÍSTICA EMPRESARIAL - 52_2024.docxATIVIDADE 1 - LOGÍSTICA EMPRESARIAL - 52_2024.docx
ATIVIDADE 1 - LOGÍSTICA EMPRESARIAL - 52_2024.docx2m Assessoria
 
Padrões de Projeto: Proxy e Command com exemplo
Padrões de Projeto: Proxy e Command com exemploPadrões de Projeto: Proxy e Command com exemplo
Padrões de Projeto: Proxy e Command com exemploDanilo Pinotti
 
Assessement Boas Praticas em Kubernetes.pdf
Assessement Boas Praticas em Kubernetes.pdfAssessement Boas Praticas em Kubernetes.pdf
Assessement Boas Praticas em Kubernetes.pdfNatalia Granato
 
ATIVIDADE 1 - GCOM - GESTÃO DA INFORMAÇÃO - 54_2024.docx
ATIVIDADE 1 - GCOM - GESTÃO DA INFORMAÇÃO - 54_2024.docxATIVIDADE 1 - GCOM - GESTÃO DA INFORMAÇÃO - 54_2024.docx
ATIVIDADE 1 - GCOM - GESTÃO DA INFORMAÇÃO - 54_2024.docx2m Assessoria
 
Boas práticas de programação com Object Calisthenics
Boas práticas de programação com Object CalisthenicsBoas práticas de programação com Object Calisthenics
Boas práticas de programação com Object CalisthenicsDanilo Pinotti
 

Último (6)

ATIVIDADE 1 - CUSTOS DE PRODUÇÃO - 52_2024.docx
ATIVIDADE 1 - CUSTOS DE PRODUÇÃO - 52_2024.docxATIVIDADE 1 - CUSTOS DE PRODUÇÃO - 52_2024.docx
ATIVIDADE 1 - CUSTOS DE PRODUÇÃO - 52_2024.docx
 
ATIVIDADE 1 - LOGÍSTICA EMPRESARIAL - 52_2024.docx
ATIVIDADE 1 - LOGÍSTICA EMPRESARIAL - 52_2024.docxATIVIDADE 1 - LOGÍSTICA EMPRESARIAL - 52_2024.docx
ATIVIDADE 1 - LOGÍSTICA EMPRESARIAL - 52_2024.docx
 
Padrões de Projeto: Proxy e Command com exemplo
Padrões de Projeto: Proxy e Command com exemploPadrões de Projeto: Proxy e Command com exemplo
Padrões de Projeto: Proxy e Command com exemplo
 
Assessement Boas Praticas em Kubernetes.pdf
Assessement Boas Praticas em Kubernetes.pdfAssessement Boas Praticas em Kubernetes.pdf
Assessement Boas Praticas em Kubernetes.pdf
 
ATIVIDADE 1 - GCOM - GESTÃO DA INFORMAÇÃO - 54_2024.docx
ATIVIDADE 1 - GCOM - GESTÃO DA INFORMAÇÃO - 54_2024.docxATIVIDADE 1 - GCOM - GESTÃO DA INFORMAÇÃO - 54_2024.docx
ATIVIDADE 1 - GCOM - GESTÃO DA INFORMAÇÃO - 54_2024.docx
 
Boas práticas de programação com Object Calisthenics
Boas práticas de programação com Object CalisthenicsBoas práticas de programação com Object Calisthenics
Boas práticas de programação com Object Calisthenics
 

Destaque

How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Applitools
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at WorkGetSmarter
 
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...DevGAMM Conference
 
Barbie - Brand Strategy Presentation
Barbie - Brand Strategy PresentationBarbie - Brand Strategy Presentation
Barbie - Brand Strategy PresentationErica Santiago
 
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them wellGood Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them wellSaba Software
 
Introduction to C Programming Language
Introduction to C Programming LanguageIntroduction to C Programming Language
Introduction to C Programming LanguageSimplilearn
 

Destaque (20)

How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
 
ChatGPT webinar slides
ChatGPT webinar slidesChatGPT webinar slides
ChatGPT webinar slides
 
More than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike RoutesMore than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike Routes
 
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
 
Barbie - Brand Strategy Presentation
Barbie - Brand Strategy PresentationBarbie - Brand Strategy Presentation
Barbie - Brand Strategy Presentation
 
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them wellGood Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
 
Introduction to C Programming Language
Introduction to C Programming LanguageIntroduction to C Programming Language
Introduction to C Programming Language
 

Tecnologia em análise e Desenvolvimento de sistemas-fila.pdf

  • 1. Tecnologia em Análise e Desenvolvimento de Sistemas Estruturas de dados I ED1A2 - FILA
  • 2. FILA ● Análogo a uma fila de banco ● Sempre o primeiro da fila é atendido ● Quando alguém chega vai para o final da fila ● FIFO (First In First Out), ou seja, o primeiro elemento que entra é o primeiro a sair.
  • 3. FILA • As inserções são feitas sempre no FINAL • As retiradas são feitas sempre do INÍCIO
  • 4. FILA–OPERAÇÕES BÁSICAS • Duas operações básicas: – INSERIR (PUT/ENQUEUE): Operação utilizada para inserir um novo elemento NO FINAL DA FILA. – REMOVER (GET/DEQUEUE): Operação utilizada para remover o elemento DO INÍCIO DA FILA.
  • 5. Barbosa e Silva 2010 FILA–APONTAMENTO • Implementação NÃO SEQUENCIAL e DINÂMICA, ou seja: • Os elementos não estão necessariamente ordenados na memória • Não existe um limite máximo de tamanho previamente definido como na implementação através de arranjos! 5
  • 6. Barbosa e Silva 2010 FILA–APONTAMENTO • Cada célula contém o VALOR propriamente dito e um apontador que aponta para o próximo item da fila. • Existe uma célula que aponta para o primeiro e outra para o último. • Quando a fila está vazia, primeiro e último apontam para null. 6
  • 8. FILA–INSERIR • A operação INSERIR é dividida em 5 etapas: – Criação de um novo nó para receber o valor inserido – O novo elemento passa a apontar para null – Verifica se a pilha está vazia • primeiro e último elemento aponta para novo – O último elemento passa a apontar para o novo elemento – o último elemento passa a ser o novo – Incrementa-se o tamanho da fila
  • 9. Barbosa e Silva 2010 FILA–INSERIR • Inserir o elemento 3 na pilha: • PASSO 1: Criando um novo nó • Novo aponta para NULL 9 Cont = 3
  • 10. Barbosa e Silva 2010 • PASSO 2: O último elemento passa a apontar para o novo elemento 10 FILA–INSERIR Cont = 3
  • 11. • PASSO 3: O último elemento passa a ser o novo FILA – INSERIR Cont = 3
  • 12. • PASSO 5: Incrementar o contador FILA – INSERIR Cont = 4
  • 13. 13 FILA – INSERIR (IMPLEMENTAÇÃO)
  • 14. FILA – REMOVER • A operação REMOVER é dividida em 4 etapas: – Verificar se a fila está vazia – Verificar se contém apenas um elemento – O primeiro elemento passa a ser o elemento que era apontado pelo primeiro (seguinte) – Decrementar o tamanho da pilha 14
  • 15. • PASSO 1: Verificar se a pilha está vazia • PASSO 2: Se não estiver vazia, verificar se existe apenas um elemento. Nesse caso, o apontador último passa a apontar para null 15 FILA – REMOVER ultimo = null
  • 16. • PASSO 3: Atualizar o ponteiro de primeiro (o primeiro elemento passa a ser o elemento que era apontado pelo primeiro (próximo)) 01/11/2017 Filas (Implementação utilizando Ponteiros) FILA – REMOVER Cont = 4
  • 17. • PASSO 4: Decrementar o tamanho da fila 01/11/2017 Filas (Implementação utilizando Ponteiros) 17 FILA – REMOVER Cont = 3
  • 18. Filas (Implementação utilizando Ponteiros) FILA – REMOVER (IMPLEMENTAÇÃO)
  • 19. 01/11/2017 Filas (Implementação utilizando Ponteiros) 19 FILA – IMPRIMIR (IMPLEMENTAÇÃO)
  • 20. FAÇA AS DEMAIS OPERAÇÕES COM FILA • Verifica se a fila está vazia • Verifica se a fila está cheia • Exibe o elemento do início • Exibe o elemento do fim 20
  • 21. Material de apoio Estudem também http://www.each.usp.br/digiampietri/ed/aula12.pdf
  • 22. Exercício Sala 1) Crie uma estrutura de fila que faça apenas as operações de ENQUEUE, DEQUEUE e EXIBIR elementos do tipo int. Utilize apenas estruturas dinâmicas 2) Altere o exercício anterior de modo a realizar as demais operações.: Verifica se a fila está vazia Verifica se a fila está cheia Exibe o elemento do início Exibe o elemento do fim
  • 23. Exercício (extra) 1. Crie uma estrutura que faça apenas as operações de inserir, remover e exibir. Cada posição deve armazenar uma operação do tipo string referenciando o movimento de um jogo de xadrez. Por exemplo Be5 (bispo se move para e5), Cf3 (cavalo se move para f3). A alocação deve ser dinâmina. 2. Altere o exercício anterior de modo a realizar as demais operações.