mhdew

Delete sub function

Mar 3rd, 2018
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.27 KB | None | 0 0
  1. void del(int pos)
  2. {
  3.     node *current=head;
  4.     node *prev;
  5.     int count=1;
  6.     if(pos==1){
  7.         head=head->next;
  8.         free(current);
  9.     }
  10.     else{
  11.         while(count<pos){
  12.             prev=current;
  13.             current=current->next;
  14.             count++;
  15.         }
  16.         prev->next=current->next;
  17.         free(current);
  18.     }
  19. }
Advertisement
Add Comment
Please, Sign In to add comment