![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiR1_xsS6Uq9vdDaenGvAKiqfm5NyOFp1VqGYzqYoQDDyoMAdB-RhqynCM7W6kUrQOHwxV_4aBinnk9uFdgAjz1GX40nNekq8Yjoy6qMC2ResCBkju9eKKMFKN0ekrCgdAxbXSTuObyPSM/s640/FIRSTNBODE.png)
#include<stdio.h>
#include<conio.h>
typedef struct list
{
int data;
struct list *next;
}node;
node *ptr;
node *start=NULL;
node *creat(node*);
node *display(node*);
int countnode(node*);
void delfirst();
void main()
{
int option,c=0;
clrscr();
do
{
printf("\n Main Menu");
printf("\n1:Creat list");
printf("\n2:Display list");
printf("\n3:Count node");
printf("\n4:delete first node");
printf("\n0:Exit\n");
printf("\nEnter your option:-");
scanf("%d",&option);
switch(option)
{
case 1:start=creat(start);
printf("\nlinked list created");
break;
case 2:start=display(start);
break;
case 3:c=countnode(start);
printf("\nThese are %d node in list\n",c);
break;
case 4:delfirst();
printf("node deleted successful");
break;
case 0:
exit(0);
}
}
while(option!=0);
getch();
}
node *creat(node *start)
{
node *ptr,*newnode;
int num;
printf("Enter data,pres 999 to exit:-");
scanf("%d",&num);
while(num!=999)
{
newnode=(node*)malloc(sizeof(node));
newnode->data=num;
if(start==NULL)
{
newnode->next=NULL;
start=newnode;
}
else
{
ptr=start;
while(ptr->next!=NULL)
ptr=ptr->next;
ptr->next=newnode;
newnode->next=NULL;
}
printf("Enter another data:-");
scanf("%d",&num);
}
return start;
}
node* display(node* start)
{
node *ptr;
ptr=start;
while(ptr!=NULL)
{
printf("\%d->",ptr->data);
ptr=ptr->next;
}
return start;
}
int countnode(node* start)
{
node *ptr;
int x=0;
ptr=start;
while(ptr!=NULL)
{
x++;
ptr=ptr->next;
}
return x;
}
void delfirst()
{
ptr=start;
ptr=ptr->next;
start=ptr;
}
Post a Comment