Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- typedef struct node
- {
- int info;
- struct node *next;
- }lista;
- lista *p, *q, *prim = NULL;
- void add(int i)
- {
- p = (lista*)malloc(sizeof(lista));
- p->info = i;
- p->next = NULL;
- if(prim == NULL)
- prim = p;
- else
- q->next = p;
- q = p;
- }
- void show()
- {
- for(p = prim; p != NULL; p = p->next)
- printf("%d\n", p->info);
- }
- void remover(int i)
- {
- for (p = prim; p != NULL; p = p->next)
- {
- if (p->info == i)
- {
- if(p == prim)
- prim = prim->next;
- else
- q->next = p->next;
- free(p);
- break;
- }
- q = p;
- }
- }
- int main(void)
- {
- int i, num;
- for(i = 1; i <= 3; i++)
- add(i);
- show();
- printf ("Informa o valor a ser apagado (1,2,3): ");
- scanf("%d",&num);
- remover(num);
- show();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement