//Creating Nodes in Singly Linked List Using Structure.
#include<iostream.h>
using namespace std;
struct node
{
char info;
node *link;
};
int main()
{
node *start,*p,*temp;
start=p=NULL;
char ch;
do
{
char item;
cout<<"Input Element to info :";
cin>>item;
temp=new node;
temp->info=item;
temp->link=NULL;
if(start==NULL)
start=temp;
else
p->link=temp;
p=temp;
cout<<"Create More Nodes y or n :";
cin>>ch;
}while(ch=='y');
//printing nodes
p=start;
while(p)
{
cout<<p->info;
p=p->link;
}
return 0;
}
#include<iostream.h>
using namespace std;
struct node
{
char info;
node *link;
};
int main()
{
node *start,*p,*temp;
start=p=NULL;
char ch;
do
{
char item;
cout<<"Input Element to info :";
cin>>item;
temp=new node;
temp->info=item;
temp->link=NULL;
if(start==NULL)
start=temp;
else
p->link=temp;
p=temp;
cout<<"Create More Nodes y or n :";
cin>>ch;
}while(ch=='y');
//printing nodes
p=start;
while(p)
{
cout<<p->info;
p=p->link;
}
return 0;
}
No comments:
Post a Comment