linked list in C
-
well im trying to delete some nodes from my list and search for them using 2 different functions problem is that deleteNode it just doesnt work (not even an error msgs) when i activate the print list function it stays the same could someoen help me with this? deletes the node: numStruct* deleteNode(numStruct** firstNode, numStruct* nodeToDelete) { numStruct* currNode = *firstNode; numStruct* temp; // if the list is not empty if (*firstNode) { // the first node should be deleted if (currNode == nodeToDelete) { *firstNode = (*firstNode)->Next; free(currNode); } else { while (nodeToDelete != currNode->Next && currNode->Next) { currNode = currNode->Next; } if (nodeToDelete == currNode->Next && nodeToDelete) { temp = currNode->Next; currNode->Next = temp->Next; free(temp); } } } printf("\n\n"); } this is my main: case 2: { numStruct* t = anchorNode; int arr[50] = { 261363 }, spot = 0; printf("Please enter all the numbers you want to delete and end it with - 999 \n"); while ((arr[spot] != -999) && (spot != 50)) { scanf("%d", &arr[spot]); if (arr[spot] != -999) { spot++; } } if (arr[spot] == -999) { arr[spot] = 261363; spot--; } for (int i = 0; i < spot; i++) { int flag = 0; while ((t->number != arr[i]) && (t->number != NULL)) { t = t->Next; if (t->number == arr[i]) { flag = 1; } } if (flag == 1) { deleteNode(anchorNode, t); t = anchorNode; } } break; }
-
well im trying to delete some nodes from my list and search for them using 2 different functions problem is that deleteNode it just doesnt work (not even an error msgs) when i activate the print list function it stays the same could someoen help me with this? deletes the node: numStruct* deleteNode(numStruct** firstNode, numStruct* nodeToDelete) { numStruct* currNode = *firstNode; numStruct* temp; // if the list is not empty if (*firstNode) { // the first node should be deleted if (currNode == nodeToDelete) { *firstNode = (*firstNode)->Next; free(currNode); } else { while (nodeToDelete != currNode->Next && currNode->Next) { currNode = currNode->Next; } if (nodeToDelete == currNode->Next && nodeToDelete) { temp = currNode->Next; currNode->Next = temp->Next; free(temp); } } } printf("\n\n"); } this is my main: case 2: { numStruct* t = anchorNode; int arr[50] = { 261363 }, spot = 0; printf("Please enter all the numbers you want to delete and end it with - 999 \n"); while ((arr[spot] != -999) && (spot != 50)) { scanf("%d", &arr[spot]); if (arr[spot] != -999) { spot++; } } if (arr[spot] == -999) { arr[spot] = 261363; spot--; } for (int i = 0; i < spot; i++) { int flag = 0; while ((t->number != arr[i]) && (t->number != NULL)) { t = t->Next; if (t->number == arr[i]) { flag = 1; } } if (flag == 1) { deleteNode(anchorNode, t); t = anchorNode; } } break; }
i'd start looking here:
numStruct* deleteNode(numStruct** firstNode, numStruct* nodeToDelete)
fn takes a pointer to a pointer to a numStruct. but here:
numStruct* t = anchorNode;
...
deleteNode(anchorNode, t);you're just passing a pointer to a numStruct.