modify element of list vs pointer code example
Example: how to change the value of a node in a linked list in c
typedef struct node{
int value;
struct node *next;
}node;
node *ammendValue(node *head, int index, int val){
node *tmp = head;
int count = 0;
if(index > len(head)){
return NULL;
}
if(index == -1){
while(count < len(head)-1){
tmp = tmp->next;
count += 1;
}
tmp->value = val;
return head;
}
if(index == 0){
head->value = val;
return head;
}
while(count < index){
tmp = tmp->next;
count += 1;
}
tmp->value = val;
return head;
}