void deleteNode(node *&head, int position) { if (position == 1) { node *temp = head; head = head->next; temp->next = NULL; delete temp; } else { node *curr = head; node *prev = NULL; int cnt = 1; while (cnt < position) { prev = curr; curr = curr->next; cnt++; } prev->next = curr->next; curr->next = NULL; delete curr; } }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter