Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <stdbool.h>
- typedef struct No {
- int x,size;
- struct No *prox;
- struct No *inicio;
- struct No *fim;
- }fila;
- int tam=0;
- fila *fila_cria(void)
- {
- fila *p = (fila *) malloc(sizeof(fila));
- if (p == NULL)
- fprintf(stderr,"erro");
- else
- p->inicio = NULL;
- p->fim = NULL;
- p->size =0;
- return p;
- }
- bool isEmpty(fila *f)
- {
- if (f->inicio == NULL)
- return 0;
- else
- return 1;
- }
- fila* inserir(fila *f,int v)
- {
- fila *no = (fila *) malloc(sizeof(fila));
- if (no == NULL)
- fprintf(stdout," sdasdsa ");
- no->x =v;
- no->prox = NULL;
- if (!isEmpty(no)){
- printf("vazia \n");
- f->inicio = no;
- }else{
- f->fim->prox = no;
- }
- no->size++;
- f->fim =no;
- return no;
- }
- void imprime(fila **f)
- {
- fila *p;
- p = (*f);
- printf("[%d] \n",(*f)->size);
- //printf("[%d] \t\n",tam);
- for(; p!= NULL; p = p->prox){
- printf("%d \n",p->x);
- }
- }
- int main()
- {
- fila *f = fila_cria();
- int num,opc;
- for(;;){
- printf("opc ");
- printf("> ");
- scanf("%d",&opc);
- switch(opc){
- case 1:
- scanf("%d",&num);
- f=inserir(f,num);
- break;
- case 2:
- imprime(&f);
- break;
- default:
- break;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement