Write a C program for Linklist....
#include<stdio.h>
#include<conio.h>
typedef struct employee
{
int empno;
char name[20];
int age;
struct linklist *next;
}emp;
void insert();
void search();
void display();
emp *p=NULL,*TOS=NULL,*t=NULL;
int main()
{
int ch;
do
{
printf("\n----------------------\n");
printf("\nList Of Choice:
");
printf("\n1-Insertion");
printf("\n2-Searching");
printf("\n3-Display");
printf("\n4-Exit");
printf("\nEnter Your Choice:
");
scanf("%d",&ch);
switch(ch)
{
case 1:
insert();
break;
case 2:
search();
break;
case 3:
display();
break;
case 4:
printf("\nPlease Press Enter to Exit");
break;
default:
printf("\nWrong Choice!! Try Again!!");
}
}
while(ch!=4);
getch();
return 0;
}
void insert()
{
p=(emp*)malloc(sizeof(emp));
printf("\nEnter Employee Number: ");
scanf("%d",&p->empno);
fflush(stdin);
printf("\nEnter Employee Name: ");
gets(p->name);
printf("\nEnter Employee Age: ");
scanf("%d",&p->age);
p->next=NULL;
if(TOS==NULL)
{
TOS=p;
}
else
{
t=TOS;
while(t->next!=NULL)
{
t=t->next;
}
t->next=p;
}
}
void search()
{
int n,c=0;
printf("\nEnter the Employee Number to be
searched: ");
scanf("%d",&n);
p=TOS;
while(p!=NULL)
{
if(p->empno==n)
{
printf("\nEmployee
Number: %d",p->empno);
printf("\nEmployee
Name: ");
puts(p->name);
printf("Employee
Age: %d",p->age);
c++;
p=p->next;
break;
}
}
if(c==0)
printf("\nNo Records
Found");
}
void display()
{
p=TOS;
if(TOS==NULL)
printf("\nNO RECORD
FOUND");
while(p!=NULL)
{
printf("\nEmployee Number:
%d",p->empno);
printf("\nEmployee Name:
");
puts(p->name);
printf("Employee Age:
%d",p->age);
p=p->next;
}
}
DEFINITION
A linked list is a complex data structure, especially useful in
systems or applications programming. A linked list is comprised of a series of
nodes, each node containing a data element, and a pointer to the next node


No comments:
Post a Comment