#include<conio.h>
#include<iostream.h>
#include<stdlib.h>
#include<fstream.h>
#include<stdio.h>

struct node
{
int data;
node *next;
};
/////////////////////////////////////////////////////

node * add(node* start)
{
node *p,*t;
p=new node;
cin>>p->data;
p->next=NULL;

if(start==NULL){
start=p;
	}//if
else {
t=start;
while(t->next){
t=t->next;
}/////////////end while
t->next=p;
}////////////else
return (start);
} //////////add1

void print(node* start){
node*p;
p=start;
cout<<endl;
while(p){
cout<<p->data;
 p=p->next;
 }
}////////////////////////////////end print
node * del(node* start,int y)
{
node *p=start,*q;
q=start;
while(p->data !=y && p){
q=p;
p=p->next;
}//end while
if(p==start)
{start=p->next;
 delete p;
 }
else  {
q->next=p->next;
delete p;}
return(start);
}//end del

node * invers(node* start){
node *q,*p=start;
node *first=NULL;
while(p!=NULL){
q=new node;
q->data=p->data;
q->next=NULL;
if(!first){
first=q;}
else{
q->next=first;
first=q;

}
p=p->next;
}
print(first);
getch();
return first;
}////////////////////////////////////////end inverse
void tagharon(node* start,node* first){
node* p=first;
node* q=start;
int x;
while(p!=NULL&&q!=NULL){
if(p->data==q->data)
x=1;
else {x=0;break; }
p=p->next;
q=q->next;
}//end while
if(x==1) cout<<"Motagharen ast!";
else cout<<"motagharen nist!";
getch();
}/////////////////////end tagharon

void edghamsort(){
node*start1=NULL,*start2=NULL,*start3=NULL,*p,*q,*temp;
int i,j;
cout<<"List1";
for(i=0;i<=4;i++){
start1=add(start1);
}
cout<<"List2";
for(j=0;j<=6;j++){
start2=add(start2);
}
p=start1;
q=start2;
while(p&&q){
 temp=new node;
 temp->next=NULL;

 if(p->data<q->data){
  temp->data=p->data;
  p=p->next;}
 else{

  temp->data=q->data;
  q=q->next;}

 if(!start3){
  start3=temp;
 }
 else{
 node* f;
 f=start3;
 while(f->next!=NULL)
  f=f->next;

 f->next=temp;

   }
}
  if( q==NULL&&p!=NULL){
  while(p)
  {
  node *n;
  n=new node;
  n->next=NULL;
  n->data=p->data;

  node * p1=start3;
  while (p1->next)
    p1=p1->next;
  p1->next=n;
  p=p->next;
  }
}
 if(p==NULL&&q!=NULL)
 {
  while(q)
  {
  node *n;
  n=new node;
  n->next=NULL;
  n->data=q->data;

  node * q1=start3;
  while (q1->next)
    q1=q1->next;
  q1->next=n;
  q=q->next;
  }
}
 print(start3);
 getch();
 }



/////////////////////////////////////////////////////
void main(){
clrscr();
node* start,*first;
node* p;
start=NULL;
int x,y;
while(1){
cout<<endl<<"Enter 1 for add OR 2 for print OR 3 for delete Or 4 For Inverse Or 5 for tagharon type 6 for sort Or 7 for exit :";
cin>>x;
switch(x){
case 1: start=add(start);break;
case 2: print(start);break;
case 3:cout<<"Enter Number For Delete:"; cin>>y; start=del(start,y);break;
case 4:cout<<"Inverse data:";first=invers(start); break;
case 5:tagharon(start,first);
case 6:edghamsort();
case 7:exit(1);
     }//sw
     }//end while
     }//main

