Simple List in Data Structures : Insertion into a singly-linked list has two special cases. It’s insertion a new node before the head (to the very beginning of the list) and after the tail (to the very end of the list). In any other case, new node is inserted in the middle of the list and so, has a predecessor and successor in the list.
Add in Start function in Simple List
void AddInStart(){ if(i>=5) {cout<<"Array is Full"; } else {for(int j=i;j>=0;j--) { num[j+1]=num[j]; } cout<<"Enter Value: "; cin>>num[0]; i++; }}
Add in END function in Simple List
void AddInEnd(){ if(i>=5) { cout<<"Array is Full"; else { cout<<"Enter Value: "; cin>>num[i]; i++; }}
Add in specific Location function in Simple List
void add_in_spacific_loc(){ if(i==5) { cout<<"Array is Full"; } else {int l; cout<<"Enter Location: "; cin>>l; l--; for(int j=i;j>=l;j--) { num[j+1]=num[j]; } cout<<"Enter Value: "; cin>>num[l]; i++; }}
Add Before a specific number function in Simple List
void add_before_No(){ if(i==5) { cout<<"Array is Full"; } else {int v; cout<<"Enter Value: "; cin>>v; for(int j=0;j<i;j++) { if(num[j]==v) { cout<<"value Found!"<<endl; for(int k=i;k>=j;k--) { num[k+1]=num[k]; } cout<<"Enter Value: "; cin>>num[j]; cout<<"Value Added Succesfully"<<endl; i++; break; }} }}
Add After a specific number function in Simple List
void add_after_No(){ if(i==5) { cout<<"Array is Full"; } else {int v; cout<<"Enter Value: "; cin>>v; for(int j=0;j<i;j++) { if(num[j]==v) { j++; cout<<"value Found!"<<endl; for(int k=i;k>=j;k--) { num[k+1]=num [k]; } cout<<"Enter Value: "; cin>>num[j]; cout<<"Value Added Succesfully"<<endl; i++; break; }}}}
Remove From start function in Simple List
void RemoveFrmStart(){ if(i==0) cout<<"Error!There is no Value in Start..."<<endl; else {for(int j=0;j<i;j++) { num[j]=num[j+1];} i--;}
Remove From END in Simple List
void RemoveFrmEnd(){ if(i==0) cout<<"Error!There is no Value in End..."<<endl; else {i--;}
Remove By specific Number in Simple List
void byNoRemove(){ int x; cout<<"Enter Value: "; cin>>x; for(int j=0;j<i;j++) { if(num[j]==x){ cout<<"Value Found!\nValue Removed Succesfully"<<endl; for(int k=j;k<i;k++) { num[k]=num[k+1]; } i--; break;}} }
Remove a number By specific location in Simple List
void byloc(){ int l; if(i==0) cout<<"Error!Array is Empty"<<endl; else { cout<<"Enter Number Location: "; cin>>l; l--; for(int j=0;j<i;j++) { if(j==l) { for(int k=j;k<i;k++) num[k]=num[k+1]; i--;}}}}
Remove From start in Simple List
void byNoReplace(){ int x; cout<<"Enter Value: "; cin>>x; for(int j=0;j<=i;j++) {if(num[j]==x) { cout<<"Value Found!\nEnter New Value"; cin>>num[j]; break;}} }
Display function in Simple List
void show(){ if(i==0) cout<<"Array is Empty"<<endl; else { for(int j=0;j<i;j++) { cout<<"Index:"<<j<<"\t\tValue:"<<num[j]<<endl; }}}
Search function in Simple List
void search(){ int n; cout<<"Enter Value to search: "; cin>>n; for(int j=0;j<i;j++) { if(num[j]==n) {cout<<"Result Found!"<<endl; cout<<"Value: "<<num[j]<<endl; break;}} }