Name-Rahul Anand REG. NO-18BEC1161: 1) #Include #Include Using Namespace STD
Name-Rahul Anand REG. NO-18BEC1161: 1) #Include #Include Using Namespace STD
REG. NO-18BEC1161
1)
#include<iostream>
#include<string>
class node
public:
char data;
node *next;
};
if((*head)==NULL)
n->data=d;
n->next=NULL;
*head=n;
return;
}
n->data=d;
n->next=*head;
*head=n;
while(head)
cout<<(head)->data<<" ";
head=(head)->next;
int main()
string s;
node *head=NULL;
cin>>s;
for(int i=0;i<s.length();i++)
push(&head,s[i]);
}
print(head);
2)
#include<iostream>
class node
public:
int data;
node *next;
};
temp->data=x;
temp->next=*head;
*head=temp;
}
node *head=NULL;
node *temp1=*head1;
node *temp2=*head2;
if(temp1->data>temp2->data)
insert(&head,temp1->data);
temp1=temp1->next;
else if(temp1->data<temp2->data)
insert(&head,temp2->data);
temp2=temp2->next;
else
insert(&head,temp2->data);
insert(&head,temp1->data);
temp1=temp1->next;
temp2=temp2->next;
}
}
if(temp1)
insert(&head,temp1->data);
else if(temp2)
insert(&head,temp2->data);
return head;
int main()
int n;
cin>>n;
node* head1=NULL;
node* head2=NULL;
while(n--)
int x;
cin>>x;
insert(&head1,x);
int o;
cin>>o;
while(o--)
int x;
cin>>x;
insert(&head2,x);
node *head=NULL;
head=merge(&head1,&head2);
cout<<"new list"<<endl;
while(head)
cout<<head->data<<endl;
head=head->next;
}
3)
#include<iostream>
class node
public:
int data;
node *next;
};
node *temp=*head;
node *pre=*head;
while(temp)
if(temp->data==x)
pre->next=temp->next;
free(temp);
break;
pre=temp;
temp=temp->next;
temp->data=x;
temp->next=*head;
*head=temp;
int main()
{
int a,n;
cin>>n;
node* head=NULL;
while(n--)
int x;
cin>>x;
insert(&head,x);
//reverse(&head);
cin>>a;
while(a--)
int x;
cin>>x;
pres(&head,x);
insert(&head,x);
node *temp=head;
while(temp)
cout<<temp->data<<endl;
temp=temp->next;
}
4)
#include<iostream>
#include<string>
class node
public:
int data;
node *next;
};
void enqueue(node **head,node **last,int d)
n->data=d;
n->next=NULL;
if(*head==NULL)
*head=n;
*last=n;
else
(*last)->next=n;
*last=n;
int p=((*head)->data);
*head=(*head)->next;
return (p);
}
void print(node **head)
int p=((*head)->data);
cout<<p<<" ";
*head=(*head)->next;
int main()
node *head=NULL;
node *last=head;
int i,j,n,k;
cin>>n;
for(i=0;i<n;i++)
cin>>k;
enqueue(&head,&last,k);
while(head)
int p= dequeue(&head);
if(p%2!=0)
cout<<p<" ";
break;
while(head)
print(&head);
5)
#include<iostream>
#include<string>
public:
char data;
node *next;
};
n->data=d;
n->next=*head;
*head=n;
char p=(*head)->data;
*head=(*head)->next;
return (p);
int main()
{
node *head=NULL;
string s1,s2;
cin>>s1;
int i;
for(i=0;i<s1.length();i++)
push(&head,s1[i]);
cin>>s2;
cout<<"\n";
for(i=0;i<s2.length();i++)
push(&head,s2[i]);
string s3="";
cout<<"\n";
while(head)
s3=s3+pop(&head);