Repository navigation
Expand file tree
/
Copy pathlistaligadafila.cpp
More file actions
executable file
·91 lines (81 loc) · 2.03 KB
/
Copy pathlistaligadafila.cpp
File metadata and controls
executable file
·91 lines (81 loc) · 2.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#include <stdlib.h>
#include <stdio.h>
struct no {
int info;
struct no * prox;
};
void imprimir (struct no * lt );
void inserir_final (int valor, struct no ** lt);
int remover_inicio (struct no ** lt);
int main () {
struct no * lista = NULL; //inicializacao da lista: lista vazia
int opcao, elem;
do {
printf ("\n 1-inserir na fila");
printf ("\n 2-remover da fila");
printf ("\n 3-imprimir fila 0-sair : ");
scanf ("%d", &opcao);
switch (opcao) {
case 1 : printf ( "\n***Inserindo na fila***");
printf ("\nValor a ser inserido: ");
scanf ("%d", &elem);
inserir_final (elem, &lista);
imprimir (lista);
break;
case 2 : printf ( "\n***Removendo da fila***");
if (lista != NULL) {
elem = remover_inicio (&lista);
printf ("\nValor removido: %d ", elem);
}
else
printf ("\Fila Vazia!");
imprimir (lista);
break;
case 3 : imprimir (lista);
break;
case 0 : printf ("\nSaindo....");
break;
default: printf ("\nOpcao Invalida!");
}
} while (opcao != 0);
system ("pause");
return (0);
}
void inserir_final (int valor, struct no ** lt)
{
struct no * aux, * temp;
aux = (struct no *) malloc (sizeof(struct no));
if (aux != NULL) {
aux->info = valor;
aux->prox = NULL;
if ( *lt == NULL ) // lista vazia
*lt = aux;
else {
temp = * lt;
while (temp->prox != NULL)
temp = temp->prox;
temp->prox = aux;
}
}
else
printf("\nMemoria insuficiente!");
}
int remover_inicio (struct no ** lt)
{
struct no * aux;
int valor;
aux = *lt;
valor = aux->info;
*lt = aux->prox;
free (aux);
return valor;
}
void imprimir (struct no * lt )
{
printf ("\nLista: ");
while (lt != NULL) {
printf ( "%d ", lt->info );
lt = lt->prox;
}
printf ("\n");
}