Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void deleteKey(NodeT* hTable[M], int key)
- {
- int numarCasuta=hFunction(key);
- if (hTable[numarCasuta] == NULL) {
- return;
- }
- NodeT* nodDeSters = NULL; /// Ca sa dealocam la final nodul scos
- if (hTable[numarCasuta]->val == key) { /// primul din lista e cel ce trebuie sters
- nodDeSters = hTable[numarCasuta];
- hTable[numarCasuta] = hTable[numarCasuta]->next; /// il punem pe urmatorul -> primul
- }
- else {
- NodeT* p = hTable[numarCasuta]; /// Parcurgem lista, cautand numarul
- while (p->next != NULL) { /// Nu suntem la ultimul element din lista
- if (p->next->val == key) { /// urmatorul lui P trebuie sters
- nodDeSters = p->next;
- p->next = p->next->next; /// urmatorul lui P devine urmatorul urmatorului lui P
- break;
- }
- }
- }
- free(nodDeSters); /// Dealocare
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement