Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void insertNodeAt(List* myList, Node* myNode, int pos) {
- Node* insertBefore = myList->head; // Börja på början av listan
- for (int p = 0; p < pos && insertBefore != NULL; p++) insertBefore = insertBefore->next; // Hoppa fram "pos" antal steg
- if (insertBefore != NULL) { // Det finns åtminstone en nod i listan
- if (pos > 0) insertBefore->previous->next = myNode; // Sätt "next" på noden innan
- insertBefore->previous = myNode; // Sätt "previous" på noden efter
- }
- if (pos == 0) myList->head = myNode; // Sätt ny start
- if (pos == myList->counter) myList->tail = myNode; // Sätt nytt slut
- myList->counter++; // Öka antal
- }
Advertisement
Add Comment
Please, Sign In to add comment