DavidNorgren

Untitled

Aug 8th, 2014
259
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.42 KB | None | 0 0
  1. void insertNodeAt(List* myList, Node* myNode, int pos) {
  2.     Node* insertBefore = myList->head;
  3.     for (int p = 0; p < pos && insertBefore != NULL; p++) insertBefore = insertBefore->next;
  4.     if (insertBefore != NULL) {
  5.         if (pos > 0) insertBefore->previous->next = myNode;
  6.         insertBefore->previous = myNode;
  7.     }
  8.     if (pos == 0) myList->head = myNode;
  9.     if (pos == myList->counter) myList->tail = myNode;
  10.     myList->counter++;
  11. }
Advertisement
Add Comment
Please, Sign In to add comment