#include <iostream>
using namespace std;
class node{
public:
int data;
node* next;
};
node* head;
node* tail;
void create(){
int n,val;
cin>>n;
for(int i=0;i<n;i++){
cin>>val;
node* temp = new node();
temp->data=val;
if(i==0){
temp->next=NULL;
head = tail = temp;
}
else{
tail->next = temp;
tail = temp;
}
}
}
void print(){
node* ptr = head;
while(ptr != NULL){
cout<<ptr->data<<"->";
ptr = ptr->next;
}
cout<<"NULL";
}
void insert_pos(int val,int pos){
int count=1;
node* p = head;
while(count<pos){
p=p->next;
count++;
}
node* temp = new node();
temp->data = val;
temp->next = p->next;
p->next = temp;
}
int main() {
create();
print();
cout<<"\n";
insert_pos(5,2);
print();
return 0;
}
To embed this program on your website, copy the following code and paste it into your website's HTML: