We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Delete a Node
Delete a Node
Sort by
recency
|
829 Discussions
|
Please Login in order to post a comment
Here is my c++ solution, you can have the video explanation here : https://youtu.be/EjWw69vLVYo
here's my solution in C language:
SinglyLinkedListNode* deleteNode(SinglyLinkedListNode* llist, int position) { SinglyLinkedListNode *fnnode = llist; if(llist == NULL || position <= -1){ return llist; } else if (position == 0){ llist = llist->next; free(fnnode); return llist; } else{ int counter = 0; while(fnnode != NULL && counter < position - 1){ fnnode = fnnode -> next; counter++; } if(fnnode != NULL && fnnode->next != NULL){ SinglyLinkedListNode *delf = fnnode -> next; fnnode -> next = fnnode->next->next; free(delf); } } return llist; }
public static SinglyLinkedListNode deleteNode(SinglyLinkedListNode llist, int position) { if (llist == null) return null; // If the list is empty, return null
Why it's not working in C#.? Is there any way to resolve in C#??
even i think so