Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void * List_set(List * self, size_t index, void * value) {
- if (self == NULL) {
- assert(self != NULL && "Rewriting empty list");
- fprintf(stderr, "Rewriting empty list");
- return NULL;
- }
- int i = 0;
- SLNode * cur = self->head;
- while (i != index && cur->next != NULL) {
- i++;
- cur = cur->next;
- }
- if (i != index) {
- assert(i == index && "Invalid index");
- fprintf(stderr, "Invalid index");
- return NULL;
- }
- void * answer = cur->value;
- cur->value = value;
- return answer;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement