Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void sterge(int k)
- {
- NOD *p = cauta(k);
- if (p == NULL)
- {
- printf("%s Nodul cu cheia (%d) nu a fost gasit in lista de nivel 1!\n", ERR_MSG, k);
- return;
- }
- if (p->hd != NULL)
- {
- if (p->hd->nxt == NULL) // nu mai exista nod in lista de nivel 2 dupa
- sterge2(k, p->hd->key);
- else
- {
- NOD2 *q;
- for (q = p->hd; q != NULL; q = q->nxt)
- sterge2(k, q->key);
- }
- }
- if (p == h) // daca nodul care trebuie sters este de fapt capul listei de nivel 1
- {
- if (p->nxt == NULL)
- {
- h = NULL;
- free(p);
- return;
- }
- h->key = h->nxt->key;
- h->val = h->nxt->val;
- NOD *tmp = h->nxt;
- free(h);
- h = tmp;
- return;
- }
- NOD *a = h; // nodul anterior celui pe care dorim sa-l stergem
- while (a->nxt != NULL && a->nxt != p)
- a = a->nxt;
- a->nxt = p->nxt;
- free(p);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement