12345678910111213141516171819202122232425262728293031323334353637
void linkedlist<itemtype>::insertnode(int index, itemtype data) { if (index < 0 || index > linkedlist::size()) { return; } else { node* temp1 = new node(); temp1->data = data; temp1->next = NULL; if (index == 0) { count++; temp1->next = head; head = temp1; return; } else { count++; node* temp2 = head; for (int i = -1; i < index - 2; i++) { temp2 = temp2->next; } temp1->next = temp2->next; temp2->next = temp1; } delete temp1; } }