Lempek

List.erase

May 24th, 2014
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.35 KB | None | 0 0
  1. void List::erase(int index){
  2.     if (index == 0){
  3.         pop_front();
  4.     }
  5.     else if (index == (n - 1)){
  6.         pop_back();
  7.     }
  8.     else{
  9.         Node* current = get_node_ptr(index);
  10.         Node* previous = get_node_ptr(index - 1);
  11.         Node* next = get_node_ptr(index + 1);
  12.  
  13.         next->previous = current->previous;
  14.         previous->next = current->next;
  15.         delete current;
  16.         --n;
  17.     }
  18. }
Advertisement
Add Comment
Please, Sign In to add comment