Escolar Documentos
Profissional Documentos
Cultura Documentos
Estrutura de Dados
Tema 4: Filas.
fim R fim
H
E 1 4 5 9
A
inicio inicio
1
15/09/2014
Operações:
• Inserir novo elemento
• Remover elemento
• Verificar se fila está vazia.
2
15/09/2014
abstract empty(fila)
SE tem algum elemento no Início retorne FALSE
SENÃO retorne TRUE
fim empty
Função Remove
abstract remove(fila)
aux fila(inicio)
fila fila – fila(inicio)
atualiza inicio
retorne aux
fim remove
3
15/09/2014
Continuando
Tema 3: Filas.
#include <stdio.h>
#include <stdlib.h>
#define TAM 100
struct fila {
char itens[TAM];
int inicio;
int fim;
};
4
15/09/2014
5
15/09/2014
int main() {
int op, el;
struct fila f;
f.inicio = 0; f.fim = -1;
do {printf(“\n1-Inserir \n2-Remover \n3-
Encerrar”);
scanf(“%d”, &op);
if(op ==1) {
printf(“\nNumero?”);
scanf(“%d”, &el);
insere(&f, el);
}
if (op ==2) {
int aux =remove(&f);
printf(“\nRemovido: %d”, aux);
}
} while (op !=3);
} //fim main
6
15/09/2014
#include <stdio.h>
#include <stdlib.h>
#define TAM 5
struct fila {
char itens[TAM];
int inicio;
int fim;
};
7
15/09/2014
int main() {
int op, el;
struct fila f;
f.inicio = f.fim = TAM - 1;
do { printf("\n1-Inserir \n2-Remover \n3-
Encerrar");
scanf("%d", &op);
if(op ==1) {
printf("\nNumero?");
scanf("%d", &el);
insere(&f, el); }
if (op ==2) {
int aux =remove(&f);
printf("\nRemovido: %d", aux);
}
} while (op !=3);
} //fim main
8
15/09/2014
Tema 4: Filas.
10 30
810AB 436C2
#include <stdio.h>
#include <stdlib.h>
struct elemento {
int num;
elemento *prox; };
struct fila {
elemento *inicio;
elemento *fim; };
9
15/09/2014
10
15/09/2014
int main() {
int op, el;
struct fila f;
f.inicio = NULL; f.fim= NULL;
do { printf("\n1-Inserir \n2-Remover
\n3-Encerrar");
scanf("%d", &op);
if(op ==1) {
printf("\nNumero?");
scanf("%d", &el);
insere(&f, el);
}
if (op ==2)
el = pop(&f);
printf("\nRemovido: %d", el);
}
} while (op !=3);
} //fim main
Finalizando
Tema 4: Filas.
11
15/09/2014
inserir_i inserir_f
remover_i remover_f
Operações em um Deque
remover_i(d) Remove do inicio do deque
inserir_i(d, e) Insere no início do deque
remover_f(d) Remove do fim do deque
inserir_f(d, e) Insere no fim do deque
empty(d) Verifica se deque está vazio
listar(d) Lista todos os elementos do deque
…
struct elemento {
int num;
struct elemento *prox;
struct elemento *ant;
};
struct deque {
struct elemento *inicio;
struct elemento *fim;
};
12
15/09/2014
13
15/09/2014
14
15/09/2014
Conclusões
15