#include<iostream.h>
#include<conio.h>
class node
{ public:
int data;
node *next;
};
void main()
{
node *start,*p;
char ch='y';
start='\0';
do
{
if (start=='\0')
{
start= new node;
p=start;
}
else
{
p->next = new node;
p=p->next;
}
cout<<"\n
Enter data ";
cin>>p->data;j++;
cout<<"\n Enter your choice (y/n)? ";
cin>>ch;
}
while(ch=='y'
|| ch=='Y');
p->next='\0';cout<<"\n--------------------------------";
cout<<"\n
Data for nodes ";
p=start;
while(p!=0)
{
cout<<"\n"<<p->data;
p=p->next;
}
cout<<"\n
Number of nodes = "<<j;
getch();
}
No comments:
Post a Comment