Created
October 17, 2017 11:55
-
-
Save mirsahib/774a65b03d17b196a6af98304a8d203f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void insertBeforeParticularItem(int searchVal,int val){ | |
int counter = 0; | |
if(head == NULL){ | |
cout<<"List is empty"<<endl; | |
}else{ | |
curr = head; | |
node* prev = NULL; | |
while(curr!=NULL){ | |
if(curr->data==searchVal){ | |
node *newNode = new node; | |
newNode->data = val; | |
if(prev==NULL){ | |
newNode->next = curr; | |
head = newNode; | |
}else{ | |
newNode->next = curr; | |
prev->next = newNode; | |
} | |
counter++; | |
break; | |
} | |
prev = curr; | |
curr=curr->next; | |
} | |
if(counter==0)cout<<"search occurrence not found"<<endl; | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment