#include<bits/stdc++.h>
using namespace std;
struct node
{
int data;
struct node *next;
}*node;
struct head
{
int count=0;
struct node *front;
struct node *rear;
}*head;
struct head1
{
int count1=0;
struct node *front1;
struct node *rear1;
}*head1;
void create_node()
{
node=(struct node*) malloc (sizeof(struct node));
node->next=NULL;
}
void create_head()
{
head=(struct head*) malloc (sizeof(struct head));
head->count=0;
head->front=NULL;
head->rear=NULL;
}
void create_head1()
{
head1=(struct head1*) malloc (sizeof(struct head1));
head1->count1=0;
head1->front1=NULL;
head1->rear1=NULL;
}
void enqueue(int data)
{
create_node();
node->data=data;
if(head->count==0)
{
head->front=node;
head->rear=node;
}
else
{
head->rear->next=node;
head->rear=node;
}
head->count++;
}
void enqueue1(int data)
{
create_node();
node->data=data;
if(head1->count1==0)
{
head1->front1=node;
head1->rear1=node;
}
else
{
head1->rear1->next=node;
head1->rear1=node;
}
head1->count1++;
}
int dequeue()
{
int x;
if(head->count==1)
{
x=head->front->data;
free(head->front);
head->front=NULL;
head->rear=NULL;
}
else
{
struct node *temp;
temp=head->front;
x=temp->data;
head->front=temp->next;
free(temp);
}
head->count--;
return x;
}
int dequeue1()
{
int x;
if(head1->count1==1)
{
x=head1->front1->data;
free(head1->front1);
head1->front1=NULL;
head1->rear1=NULL;
}
else
{
struct node *temp;
temp=head1->front1;
x=temp->data;
head1->front1=temp->next;
free(temp);
}
head1->count1--;
return x;
}
void print()
{
struct node *temp;
temp=head->front;
cout<<"The queue1 data are : ";
while(temp!=NULL)
{
cout<<temp->data<<" ";
temp=temp->next;
}
cout<<"\ntotal data "<<head->count<<endl<<endl;
}
void print1()
{
struct node *temp;
temp=head1->front1;
cout<<"The queue2 data are : ";
while(temp!=NULL)
{
cout<<temp->data<<" ";
temp=temp->next;
}
cout<<"\ntotal data "<<head1->count1<<endl<<endl;
}
void process()
{
int s=0;
if(head->count!=head1->count1)
{
cout<<"Not identical"<<endl;
}
else
{
int y=head->count;
while(y--)
{
int j,k;
j=dequeue();
k=dequeue1();
if(j!=k && s==0)
{
s=1;
enqueue(j);
enqueue1(k);
}
else
{
enqueue(j);
enqueue1(k);
}
}
if(s==1)
{
cout<<"\nNot Identical"<<endl<<endl;
}
else
{
cout<<"\nIdentical"<<endl<<endl;
}
}
}
int main()
{
create_head();
create_head1();
cout<<"Before exccution : "<<endl;
enqueue(76);
enqueue(86);
enqueue(98);
enqueue(65);
enqueue(9);
enqueue(65);
enqueue(43);
print();
enqueue1(64);
enqueue1(86);
enqueue1(98);
enqueue1(65);
enqueue1(9);
enqueue1(65);
enqueue1(43);
print1();
process();
cout<<"\nAfter exccution : "<<endl;
print();
print1();
return 0;
}
using namespace std;
struct node
{
int data;
struct node *next;
}*node;
struct head
{
int count=0;
struct node *front;
struct node *rear;
}*head;
struct head1
{
int count1=0;
struct node *front1;
struct node *rear1;
}*head1;
void create_node()
{
node=(struct node*) malloc (sizeof(struct node));
node->next=NULL;
}
void create_head()
{
head=(struct head*) malloc (sizeof(struct head));
head->count=0;
head->front=NULL;
head->rear=NULL;
}
void create_head1()
{
head1=(struct head1*) malloc (sizeof(struct head1));
head1->count1=0;
head1->front1=NULL;
head1->rear1=NULL;
}
void enqueue(int data)
{
create_node();
node->data=data;
if(head->count==0)
{
head->front=node;
head->rear=node;
}
else
{
head->rear->next=node;
head->rear=node;
}
head->count++;
}
void enqueue1(int data)
{
create_node();
node->data=data;
if(head1->count1==0)
{
head1->front1=node;
head1->rear1=node;
}
else
{
head1->rear1->next=node;
head1->rear1=node;
}
head1->count1++;
}
int dequeue()
{
int x;
if(head->count==1)
{
x=head->front->data;
free(head->front);
head->front=NULL;
head->rear=NULL;
}
else
{
struct node *temp;
temp=head->front;
x=temp->data;
head->front=temp->next;
free(temp);
}
head->count--;
return x;
}
int dequeue1()
{
int x;
if(head1->count1==1)
{
x=head1->front1->data;
free(head1->front1);
head1->front1=NULL;
head1->rear1=NULL;
}
else
{
struct node *temp;
temp=head1->front1;
x=temp->data;
head1->front1=temp->next;
free(temp);
}
head1->count1--;
return x;
}
void print()
{
struct node *temp;
temp=head->front;
cout<<"The queue1 data are : ";
while(temp!=NULL)
{
cout<<temp->data<<" ";
temp=temp->next;
}
cout<<"\ntotal data "<<head->count<<endl<<endl;
}
void print1()
{
struct node *temp;
temp=head1->front1;
cout<<"The queue2 data are : ";
while(temp!=NULL)
{
cout<<temp->data<<" ";
temp=temp->next;
}
cout<<"\ntotal data "<<head1->count1<<endl<<endl;
}
void process()
{
int s=0;
if(head->count!=head1->count1)
{
cout<<"Not identical"<<endl;
}
else
{
int y=head->count;
while(y--)
{
int j,k;
j=dequeue();
k=dequeue1();
if(j!=k && s==0)
{
s=1;
enqueue(j);
enqueue1(k);
}
else
{
enqueue(j);
enqueue1(k);
}
}
if(s==1)
{
cout<<"\nNot Identical"<<endl<<endl;
}
else
{
cout<<"\nIdentical"<<endl<<endl;
}
}
}
int main()
{
create_head();
create_head1();
cout<<"Before exccution : "<<endl;
enqueue(76);
enqueue(86);
enqueue(98);
enqueue(65);
enqueue(9);
enqueue(65);
enqueue(43);
print();
enqueue1(64);
enqueue1(86);
enqueue1(98);
enqueue1(65);
enqueue1(9);
enqueue1(65);
enqueue1(43);
print1();
process();
cout<<"\nAfter exccution : "<<endl;
print();
print1();
return 0;
}
No comments:
Post a Comment