#include<iostream>
using namespace std;
struct nodep
{
int data;
nodep *next1;
};
struct node
{
char ch;
nodep *p;
nodep *q;
node *next;
};
int search(char c,node *K)
{
while(K->next!=NULL)
{
if(K->ch==c)
{
cout<<"welcome:\n";
return 1;
}
else
if(K->next!=NULL)
K=K->next;
}
return 0;
}
void print(node *KK)
{
while(KK!=NULL)
{
cout<<KK->ch<<" ";
while(KK->q!=NULL)
{
cout<<KK->q->data<<" ";
KK->q=KK->q->next1;
}
cout<<"\n";
KK=KK->next;
}
}
int main()
{
node *L,*S;char ch1,ch2,choice;int n,y;
L=new(node);S=L;
cout<<"enter the character:\n";
cin>>ch1;
ch2=ch1;
L->ch=ch1;
cout<<"enter the data value:\n";
cin>>n;
L->p=new(nodep);
L->q=L->p;
L->p->data=n;
L->p->next1=NULL;
L->next=NULL;
cout<<"enter y to continue:\n";
cin>>choice;
while(choice=='y'||choice=='Y')
{
cout<<"enter the character:\n";
cin>>ch1;
if(ch1==ch2)
y=1;
else
y=search(ch1,S);
ch2=ch1;
if(y==1)
{
L=S;
while(L->ch!=ch1)
L=L->next;
nodep *temp;
temp=new(nodep);
cout<<"enter the data value:\n";
cin>>n;
temp->data=n;
temp->next1=NULL;
while(L->p->next1!=NULL)
L->p=L->p->next1;
L->p->next1=temp;
L->p=temp;
}
else
{
L=S;
while(L->next!=NULL)
L=L->next;
node *temp;
temp=new(node);
temp->ch=ch1;
temp->p=new(nodep);
temp->q=temp->p;
cout<<"enter the data value:\n";
cin>>n;
temp->p->data=n;
temp->p->next1=NULL;
temp->next=NULL;
L->next=temp;
L=temp;
}
cout<<"enter y to continue:\n";
cin>>choice;
}
print(S);
return 0;
}
using namespace std;
struct nodep
{
int data;
nodep *next1;
};
struct node
{
char ch;
nodep *p;
nodep *q;
node *next;
};
int search(char c,node *K)
{
while(K->next!=NULL)
{
if(K->ch==c)
{
cout<<"welcome:\n";
return 1;
}
else
if(K->next!=NULL)
K=K->next;
}
return 0;
}
void print(node *KK)
{
while(KK!=NULL)
{
cout<<KK->ch<<" ";
while(KK->q!=NULL)
{
cout<<KK->q->data<<" ";
KK->q=KK->q->next1;
}
cout<<"\n";
KK=KK->next;
}
}
int main()
{
node *L,*S;char ch1,ch2,choice;int n,y;
L=new(node);S=L;
cout<<"enter the character:\n";
cin>>ch1;
ch2=ch1;
L->ch=ch1;
cout<<"enter the data value:\n";
cin>>n;
L->p=new(nodep);
L->q=L->p;
L->p->data=n;
L->p->next1=NULL;
L->next=NULL;
cout<<"enter y to continue:\n";
cin>>choice;
while(choice=='y'||choice=='Y')
{
cout<<"enter the character:\n";
cin>>ch1;
if(ch1==ch2)
y=1;
else
y=search(ch1,S);
ch2=ch1;
if(y==1)
{
L=S;
while(L->ch!=ch1)
L=L->next;
nodep *temp;
temp=new(nodep);
cout<<"enter the data value:\n";
cin>>n;
temp->data=n;
temp->next1=NULL;
while(L->p->next1!=NULL)
L->p=L->p->next1;
L->p->next1=temp;
L->p=temp;
}
else
{
L=S;
while(L->next!=NULL)
L=L->next;
node *temp;
temp=new(node);
temp->ch=ch1;
temp->p=new(nodep);
temp->q=temp->p;
cout<<"enter the data value:\n";
cin>>n;
temp->p->data=n;
temp->p->next1=NULL;
temp->next=NULL;
L->next=temp;
L=temp;
}
cout<<"enter y to continue:\n";
cin>>choice;
}
print(S);
return 0;
}
No comments:
Post a Comment