Linked List representations of Employee Records
//Linked List
representations of Employee Records
#include<stdlib.h>
#include<stdio.h>
struct emp
{
int empno;
char *empname;
long int salary;
struct emp *next;
}*start
= NULL;
{
struct emp *temp,*ptr;
temp = malloc(sizeof(struct emp));
printf("\n Employee Number:
");
scanf("%d",&temp->empno);
printf("\n Employee Name:
");
scanf("%s",temp->empname);
printf("\n Salary: ");
scanf("%ld",&temp->salary);
temp->next =NULL;
start=temp;
else
{
ptr=start;
while(ptr->next !=NULL)
ptr=ptr->next
;
ptr->next =temp;
}
}
void
del()
{
struct
emp *ptr=start;
while
(ptr->next->next!=NULL)
ptr=ptr->next;
ptr->next=NULL;
printf("Deletion
is done at the end of record\n");
}
void display()
{
int count=0;
struct emp *ptr;
ptr=start;
printf("\n\nEmployee
Details\n");
printf("-------------------\n");
while(ptr!=NULL)
{
printf("Employee
Number: %d\n",ptr->empno);
printf("Employee
Name: %s\n",ptr->empname);
printf("Salary:
%ld\n\n", ptr->salary);
count++;
ptr=ptr->next
;
}
printf("\nTotal number of
employees is %d\n", count);
}
void
main()
{
int ch;
printf("Employee Record
Details\n");
printf("-----------------------\n");
printf("\t 1. Insert a new record\n");
printf("\t 2. Delete an
existing record\n");
printf("\t 3. Print employee
records\n");
printf("\t 4. Exit\n");
do {
printf("\nEnter
your choice [1..3]: ");
scanf("%d:",&ch);
switch(ch)
{
case 1:
insert();
break;
case 2:
del();
break;
case 3:
display();
break;
default:
printf("Choose
correct choice");
}
} while (ch!=4);
}
OUTPUT
-------------
Employee
Record Details
--------------------------------
1. Insert a new record
2. Delete an existing record
3. Print employee records
4. Exit
Enter
your choice [1..3]: 1
Employee Number: 1
Employee Name: thej
Salary: 250000
Enter
your choice [1..3]: 1
Employee Number: 2
Employee Name: deebesh
Salary: 206000
Enter
your choice [1..3]: 3
Employee
Details
----------------------
Employee
Number: 1
Employee
Name: thej
Salary:
250000
Employee
Number: 2
Employee
Name: deebesh
Salary:
206000
Total
number of employees is 2
Enter
your choice [1..3]: 2
Deletion
is done at the end of record
Enter
your choice [1..3]: 3
Employee
Details
----------------------
Employee
Number: 1
Employee
Name: thej
Salary:
250000
Comments
Post a Comment