SHARE
TWEET

Untitled

a guest Nov 14th, 2019 117 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. typedef struct node {
  2. node* next;
  3. void* value
  4. } node;
  5.  
  6. typedef struct list {
  7.     node* head;
  8. } list;
  9.  
  10. list* createList()
  11. {
  12.     list* ret = malloc(sizeof(list));
  13.     ret->head = NULL;
  14.     ret->head->next = NULL;
  15.     ret->head->value = NULL;
  16.     return ret;
  17. }
  18. list* createList(void* val)
  19. {
  20.     list* ret = malloc(sizeof(list));
  21.     ret->head = malloc(sizeof(node));
  22.     ret->head->next = NULL;
  23.     ret->head->value = val;
  24.     return ret;
  25. }
  26.  
  27.  
  28. node* insertValue(list* l, void* val)
  29. {
  30.     node* iterator = l->head;
  31.     if(l->head->next == NULL)
  32.     {
  33.         node* temp = malloc(sizeof(node));
  34.         temp->next = NULL;
  35.         temp->value = val;
  36.         l->head->next = temp;
  37.         return;
  38.     }
  39.    
  40.     while(iterator != NULL && iterator->next != NULL)
  41.     {
  42.         iterator = iterator->next;
  43.     }
  44.     node* insert = malloc(sizeof(node));
  45.     insert->next = NULL;
  46.     insert->value = val;
  47.     iterator->next = insert;
  48.     return insert;
  49. }
  50.  
  51. void deleteNode(list* l, void* val)
  52. {
  53.     node* iterator = l->head;
  54.     node* previous = iterator;
  55.     if(l->head == NULL)
  56.     {
  57.         return;
  58.     }
  59.     if(l->head->next == NULL)
  60.     {
  61.         head->value = NULL;
  62.         free(l->head);
  63.         return;
  64.     }
  65.     while(iterator != NULL && iterator->next != NULL)
  66.     {
  67.         if(iterator->value == val)
  68.         {
  69.             previous->next = iterator->next;
  70.             iterator->next = NULL;
  71.             iterator->value = NULL;
  72.             free(iterator);
  73.         }
  74.         previous = iterator;
  75.         iterator = iterator->next;
  76.     }
  77. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top