Exact similar code to insertion sort in the array easy to understand
I request you dry run once on the first exapmle itself and you will understand \njust igonre the cout<val;\n\n# Complexity\n- Time complexity:\nO(N^2)\n\n- Spac
I request you dry run once on the first exapmle itself and you will understand \njust igonre the cout<<head->val;\n\n# Complexity\n- Time complexity:\nO(N^2)\n\n- Space complexity:\nO(1)\n\n# Code\n```\n/**\n * Definition for singly-linked list.\n * struct ListNode {\n *     int val;\n *     ListNode *next;\n *     ListNode() : val(0), next(nullptr) {}\n *     ListNode(int x) : val(x), next(nullptr) {}\n *     ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n    ListNode* insertionSortList(ListNode* head) \n    {\n       if(head==NULL || head->next==NULL)return head;\n       ListNode *start=head;\n       while(start!=NULL)\n       {\n           ListNode*temp=head;\n           while(temp!=start)\n           {\n               if(temp->val > start->val)\n               {\n                  swap(temp->val,start->val);\n               }\n               temp=temp->next;\n           }\n           cout<<head->val<<" ";\n           start=start->next;\n       }\n       return head;\n                                                                           \n    }\n};\n```
['C++']