Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "linked_list.h"
- #include <stdio.h>
- struct list* create_list(int value){
- struct list* item = malloc(1,sizeof(struct list));
- item->value = value;
- item->next = NULL;
- return item;
- }
- void destroy_list(struct list* list){
- if(list!=NULL){
- destroy_list(list->next);
- free(list);
- }
- }
- struct list* pop_list(struct list* list,int* value){
- struct list* item = list;
- if(list == NULL){
- return NULL;
- }
- while (item->next != NULL){
- item = item->next;
- }
- value = item->value;
- free(item);
- return list;
- }
- struct list* push_list(struct list* list,int value){
- struct list* new_item = malloc(1,sizeof(struct list));
- new_item->next = NULL;
- new_item->value = value;
- if (list == NULL){
- return new_item;
- }
- struct list* cursor = list;
- while(cursor->next != NULL){
- cursor = cursor->next;
- }
- cursor->next = item;
- return list;
- }
- struct list* shift_list(struct list* list,int value) {
- struct list* item = malloc(1,sizeof(struct list));
- item->value = value;
- if(list == NULL){
- item->next = NULL;
- return item;
- }
- item->next = list;
- return list;
- }
- struct list* unshift_list(struct list* list,int* value){
- if(list == NULL){
- return NULL;
- }
- struct list* item = list;
- value = item->value;
- list = item->next;
- free(item);
- return list;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement