Skip to content

Instantly share code, notes, and snippets.

@mirsahib
Last active October 12, 2017 08:33
Show Gist options
  • Save mirsahib/c02d3ff1b7b9fbcbd6bffa6398692e84 to your computer and use it in GitHub Desktop.
Save mirsahib/c02d3ff1b7b9fbcbd6bffa6398692e84 to your computer and use it in GitHub Desktop.
Bug in addAt
void addAt(int index,int val){
temp = new node;
temp->data = val;
int y = temp->data;
temp->next = NULL;
y = temp->data;
if(head==NULL){
cout<<"The list is empty"<<endl;
y=temp->data;
}else if(index==0){
temp->next=head->next;
head = temp;
y=temp->data;
}else if(sizeOflist()<index){
addLast(val);
y=temp->data;
}else{
y=temp->data;
curr = head;
y=temp->data;
int x;
for(int i=0;i<index-1;i++){
x = curr->data;
curr=curr->next;
x = curr->data;
}
int i=curr->next->data;
y=temp->data;
temp->next = curr->next; //exp
int k = temp->next->data;
curr->next = temp; //exp
y = temp->data;
int j= curr->next->data;
cout<<"";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment