#include
#include
#include
struct linkedlist
{
int data;
struct linkedlist *next;
};
typedef struct linkedlist node;
void main()
{
int count=0;
node *head,*ptr,*new1;
char ch;
clrscr();
head=(node *)malloc(sizeof(node));
ptr=head;
do
{
printf("\nEnter the data\n");
scanf("%d",&ptr->data);
count++;
printf("Do you want to continue(y/n):");
ch=getch();
if(ch=='y')
{
clrscr();
ptr->next=(node *)malloc(sizeof(node));
ptr->next=new1;
ptr=ptr->next;
}
else
ptr->next=NULL;
}
while(ch!='n');

printf("\nno of nodes inthe list %d",count);
getch();
}

Comments (0)

CSS Menu Samples