Advertisement
Guest User

Untitled

a guest
Feb 19th, 2018
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.57 KB | None | 0 0
  1. void * List_set(List * self, size_t index, void * value) {
  2.  
  3.     if (self == NULL) {
  4.         assert(self != NULL && "Rewriting empty list");
  5.         fprintf(stderr, "Rewriting empty list");
  6.         return NULL;
  7.     }
  8.     int i = 0;
  9.     SLNode * cur = self->head;
  10.     while (i != index && cur->next != NULL) {
  11.         i++;
  12.         cur = cur->next;
  13.     }
  14.     if (i != index) {
  15.         assert(i == index && "Invalid index");
  16.         fprintf(stderr, "Invalid index");
  17.         return NULL;
  18.     }
  19.     void * answer = cur->value;
  20.     cur->value = value;
  21.     return answer;
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement