You are viewing a single comment's thread. Return to all comments →
C++ (more at https://github.com/IhorVodko/Hackerrank_solutions , feel free to give a star :) )
#include <cassert> DoublyLinkedListNode * sortedInsert( DoublyLinkedListNode * _list , int _data ){ assert(_list); auto node = _list; while(node->data < _data && node->next){ node = node->next; } auto nodeInserted = new DoublyLinkedListNode(_data); if(node->data < _data){ node->next = nodeInserted; nodeInserted->prev = node; return _list; } if(node->prev){ node->prev->next = nodeInserted; nodeInserted->prev = node->prev; nodeInserted->next = node; node->prev = nodeInserted; return _list; } nodeInserted->next = node; node->prev = nodeInserted; return nodeInserted; }
Seems like cookies are disabled on this browser, please enable them to open this website
Inserting a Node Into a Sorted Doubly Linked List
You are viewing a single comment's thread. Return to all comments →
C++ (more at https://github.com/IhorVodko/Hackerrank_solutions , feel free to give a star :) )