Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int list_del(list_head *list, int i){
- if(list==NULL){
- return 0;
- }
- int pos=1;
- list_node *prev = NULL;
- list_node *current = list->head;
- list_node *next = current->next;
- while(current!=NULL){
- if(pos==i && pos==1){
- free(current->data);
- free(current);
- list->head = next;
- list->list_size--;
- return 1;
- }
- if(pos==i && pos==list->list_size){
- free(current->data);
- free(current);
- prev->next = NULL;
- list->list_size--;
- return 1;
- }
- if(pos==i){
- free(current->data);
- free(current);
- prev->next = next;
- list->list_size--;
- return 1;
- }
- pos++;
- prev = current;
- current = current->next;
- next = current->next;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement