Skip to content

Instantly share code, notes, and snippets.

@mirsahib
Created August 30, 2017 13:49
Show Gist options
  • Save mirsahib/b938d7091e31b836ff81c866cacbf31e to your computer and use it in GitHub Desktop.
Save mirsahib/b938d7091e31b836ff81c866cacbf31e to your computer and use it in GitHub Desktop.
void List::insertToNthPosition(int pos,int newData){
temp = new node;
temp->data = newData;
temp->next = NULL;
if(pos==1){
head = temp;
}else{
curr = head;
for(int i=0;i<pos-2;i++){
curr=curr->next;
}
temp->next = curr->next;
curr->next=temp;
}
}
@mario1987
Copy link

code is not working

Exception thrown: read access violation.

this->temp was nullptr.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment