Removing an element from a linked list

preview_player
Показать описание
Рекомендации по теме
Комментарии
Автор

Great teacher. I really like how you explain everything more than once in different ways

tungamarkal
Автор

Awesome video and playlist on Linked List. This really helped me understand my homework in a concise but effective manner. Thanks!

Anonomyous-cgye
Автор

There is another way to remove a specific node from the list. For instance, if we need to remove elements of the list that are not from some interval [m, n]:
void fromInterval(Node** head, int n, int m) {
Node* curr = *head;
Node* prev = NULL;
while(curr != NULL) {
if(curr -> data > n || curr -> data < m) {

Node* temp = curr;
if (prev == NULL) {
*head - curr -> next;
}
else {
prev -> next = curr -> next;
}
curr = curr -> next;
free(temp);
}
else {
prev = curr;
curr = curr -> next;
}
}
}

dalibormaksimovic
Автор

Hey, I think to remove all the nodes that have the same value, it was enough for me to remove "return;" in the if statement, then it worked out

amireid
Автор

Hi man! I have been watching your videos and would like to buy you a coffee, do you have a link for that? Thank you and keep up the good work!

Emirodriguezalc
Автор

great video.
Can you please do a video on graphs in c? I need it for a pathfinding project of my school. Thanks!

yoannhoundonougbo
Автор

Hey, i attempted to implement this but ran into segmentation fault errors

mauriciofuentes
Автор

How to delete a tail element and modify the tail?

HK-rcvf
Автор

is it necessary to put "return;" in every if condition like how you did here?

Hello_am_Mr_Jello
Автор

Thanks again, solved this myself before watching this video.
void _remove(Node** root, int vl) {

if(*root == NULL)
return;

Node* aux;
if((*root)->ch == vl) {
aux = *root;
(*root) = (*root)->next;
free(aux);
return;
}

Node* current = *root;
while(current->ch != vl && current->next != NULL){
aux = current;
current = current->next;
}

if(current->next == NULL)
return;

aux->next = current->next;
free(current);
}

synacktra
Автор

what if there is only one node in the linked list though, and you want to remove it?

DataStructures