-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfila.c
80 lines (74 loc) · 1.08 KB
/
fila.c
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
#include<stdio.h>
#include<stdlib.h>
typedef struct no{
int valor;
struct no *prox;
}TNo;
/*typedef struct cabeca{
struct no *inicio;
struct no *fim;
}TCabeca;*/
void insereFim(TNo **fim, int k)
{
TNo *novo;
novo =(TNo *)malloc(sizeof(TNo));
if (novo==NULL) return;
novo->valor=k;
novo->prox = NULL;
if(*fim!=NULL)
(*fim)->prox = novo;
*fim = novo;
}
void imprimeLista(TNo *p)
{
if(p==NULL)
{
printf("\nLista vazia!");
return;
}
while(p!=NULL)
{
printf("\n%d", p->valor);
p = p->prox;
}
}
void removeInicio(TNo **p)
{
TNo *aux;
if(*p==NULL) {
printf("\nLista vazia!");
return;
}
aux = *p;
*p = (*p)->prox;
free(aux);
aux=NULL;
}
void main()
{
TNo *inicio=NULL, *fim=NULL;
int op=1, n;
while(op!=4)
{
printf("\nInforme \n1-Inserir \n2-Retirar\n3-Imprimir\n4-Sair\n:");
scanf("%d",&op);
if(op==1)
{
printf("\nValor:");
scanf("%d",&n);
insereFim(&fim,n);
if(inicio==NULL)
inicio=fim;
}
if(op==2)
{
removeInicio(&inicio);
if(inicio==NULL)
fim=inicio; //fim=NULL;
}
if(op==3)
{
imprimeLista(inicio);
}
}
}