Advertisement
Guest User

Untitled

a guest
Dec 19th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.71 KB | None | 0 0
  1. #include "linked_list.h"
  2. #include <stdio.h>
  3. struct list* create_list(int value){  
  4.   struct list* item = malloc(1,sizeof(struct list));  
  5.   item->value = value;  
  6.   item->next = NULL;  
  7.   return item;  
  8. }  
  9. void destroy_list(struct list* list){       
  10.   if(list!=NULL){  
  11.     destroy_list(list->next);  
  12.     free(list);  
  13.   }  
  14. }  
  15. struct list* pop_list(struct list* list,int* value){  
  16.   struct list* item = list;  
  17.   if(list == NULL){  
  18.     return NULL;  
  19.   }  
  20.   while (item->next != NULL){  
  21.     item = item->next;  
  22.   }  
  23.   value = item->value;  
  24.   free(item);  
  25.   return list;  
  26. }  
  27. struct list* push_list(struct list* list,int value){  
  28.   struct list* new_item = malloc(1,sizeof(struct list));  
  29.   new_item->next = NULL;  
  30.   new_item->value = value;  
  31.   if (list == NULL){  
  32.     return new_item;  
  33.    }  
  34.   struct list* cursor = list;  
  35.   while(cursor->next != NULL){  
  36.     cursor = cursor->next;  
  37.   }  
  38.   cursor->next = item;  
  39.   return list;  
  40. }  
  41.      
  42. struct list* shift_list(struct list* list,int value) {         
  43.   struct list* item = malloc(1,sizeof(struct list));  
  44.   item->value = value;  
  45.   if(list == NULL){  
  46.     item->next = NULL;  
  47.     return item;  
  48.   }  
  49.   item->next = list;  
  50.   return list;  
  51.   }  
  52.   struct list* unshift_list(struct list* list,int* value){   
  53.   if(list == NULL){  
  54.      return NULL;  
  55.   }  
  56.   struct list* item = list;  
  57.   value = item->value;  
  58.   list = item->next;  
  59.   free(item);  
  60.   return list;  
  61. }  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement