Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<conio.h>
- #include<stdlib.h>
- struct lista
- {
- int nr;
- struct lista *urmator;
- };
- typedef struct lista LI;
- void afisare2(LI *cap)
- {
- LI *aux;
- for(aux = cap;aux != NULL;aux = aux->urmator)
- {
- printf("Val(2) = %d\n",aux->nr);
- }
- printf("-----------------------\n");
- }
- LI *elimina(LI *cap)
- {
- LI *aux,*p;
- while(cap != NULL && cap->nr%2 == 0 && cap->urmator != NULL)
- {
- aux = cap;
- cap = cap->urmator;
- free(aux);
- }
- if(cap->urmator == NULL)
- {
- return NULL;
- }
- p = cap;
- while(p->urmator != NULL)
- {
- if(p->urmator->nr%2 == 0)
- {
- aux = p->urmator;
- p->urmator = p->urmator->urmator;
- free(aux);
- }
- else p = p->urmator;
- }
- return cap;
- }
- int main(void)
- {
- LI *CapDeLista,*p,*q;
- int i,n;
- printf("Introdceti numarul de elemente din lista:\n");
- scanf("%d",&n);
- p = (LI*)malloc(sizeof(LI));
- printf("Introduceti valoarea: \n");
- scanf("%d",&p->nr);
- p->urmator = NULL;
- CapDeLista = p;
- for(i=1;i<n;i++)
- {
- q = (LI*)malloc(sizeof(LI));
- printf("Introduceti valoarea: \n");
- scanf("%d",&q->nr);
- q->urmator = NULL;
- p->urmator = q;
- p = q;
- }
- afisare2(CapDeLista);
- CapDeLista = elimina(CapDeLista);
- if(CapDeLista == NULL)
- printf("Lista goala!\n");
- else afisare2(CapDeLista);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement