Untitled

 avatar
unknown
plain_text
4 years ago
5.7 kB
8
Indexable
//employee
#include <stdio.h>
	#include <stdlib.h>
	#include <string.h>

	struct node
	{
		char  name[20], adress[10], area[10];
		long int phno;
		struct node *rlink;
		struct node *llink;
	};
	typedef struct node* NODE;
	NODE first=NULL;
	int count=0;

	NODE createEmployeeNode()
	{

		NODE employee;
		employee=(NODE)malloc(sizeof(struct node));

		if(employee==NULL)
		{
		printf("Out of Memory\n");
		exit(0);
		}
		employee->rlink=NULL;
		employee->llink=NULL;

		char  name[20], adress[10], area[10];
		long int phno;


		printf("Enter Name:\t");
		scanf("%s", name);
		printf("Enter adress:\t");
		scanf("%s", adress);
		printf("Enter area:\t");
		scanf("%s",area);
		printf("Enter Phone Number:\t");
		scanf("%ld", &phno);

		strcpy(employee->name, name);
		strcpy(employee->adress, adress);
		strcpy(employee->area, area);
		employee->phno=phno;

		count++;
		return employee;
	}

	NODE insert_front()
	{
		NODE temp;
		temp=createEmployeeNode();

		if(first==NULL)
		{
		return temp;
		}

		temp->rlink=first;
		first->llink=temp;

		return temp;
	}

	NODE insert_end()
	{
		NODE cur, temp;
		temp=createEmployeeNode();

		if(first==NULL)
		{
		return temp;
		}
		cur=first;
		while(cur->rlink!=NULL)
		{
		cur=cur->rlink;
		}
		cur->rlink=temp;
		temp->llink=cur;

		temp->rlink=NULL;

		return first;

	}




	void display()
	{
		NODE cur;
		cur=first;

		if(cur==NULL)
		{
		printf("The list is empty\n");
		}
		else
		{

		printf("The contents of the list are\n");
		while(cur!=NULL)
		{
		printf(" \nName: %s\nadress: %s\narea: %s\nPhone: %ld \n", cur->name, cur->adress, cur->area, cur->phno);
		cur=cur->rlink;
		}
		printf("\nThe number of users: %d",count);
		}
	}

	void main()
	{
		int ch,i,n;
		while(1)
		{
		printf("\n\n1. Create DLL of registers\n\n\n");
		printf("2. Display\n\n\n");
		printf("3. Insert at Front\n\n\n");
		printf("4. Insert at End\n\n\n");
		printf("5. Exit\n\n\n");

		printf("Enter your choice:\t");
		scanf("%d",&ch);

		switch(ch)
		{
		case 1: printf("Enter the number of registers!\n\n\n");
		scanf("%d",&n);
		for(i=0; i<n; i++)
		first=insert_end();
		break;

		case 2: display();
		break;
		case 3: first=insert_front();
		break;
		case 4: first=insert_end();
		break;
		case 5: exit(0);
		break;
		default: printf("Invalid choice\n");
		break;

		}


		}
	}




//employee delete
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

typedef struct department
{
char name[20];
int number;
}dept;

typedef struct node
{
char ssn[10];
char name[20];
dept* dpt;
char designation[10];
int salary;
int phone_number;
int age;
struct node* prev, *next;
}node;

typedef struct employees
{
node* head;
}emp;

void init(emp* ptr)
{
  ptr->head=NULL;
}

void insert_f(emp* ptr, char* ssn, char* name, int ph, char* des, char* dpt_name, int age, int sal, int dept_num)
{
node* temp= (node*) malloc(sizeof(node));
temp->dpt= (dept*) malloc(sizeof(dept));
strcpy(temp->ssn,ssn);
strcpy(temp->name,name);
strcpy(temp->dpt->name,dpt_name);
temp->dpt->number=dept_num;
temp->salary=sal;
temp->phone_number=ph;
temp->age=age;
strcpy(temp->designation,des);
temp->prev=NULL;
temp->next=NULL;
if(ptr->head==NULL)
{
  ptr->head=temp;
  return;
}
node* p=ptr->head;
temp->next=ptr->head;
p->prev=temp;
ptr->head=temp;
}

void disp(const emp* ptr)
{
if(ptr->head==NULL)
{
  printf("no data to display\n");
  return;
}
node* p=ptr->head;
printf("\nDetails of employees:\n");
while(p!=NULL)
{
  printf("%s \t %s \t %s \t %d \t %s \t %d \t %d \t %d \n",p->ssn,p->name,p->dpt->name,p->dpt->number,p->designation, p->phone_number, p->salary, p->age);
  p=p->next;
}
printf("\n");
}

void delete_above_58(emp* ptr)
{
node* p1=ptr->head;
if(ptr->head==NULL)
{
  printf("no nodes in list\n");
  return;
}
if(p1->age>58)
{
  ptr->head=p1->next;
  p1->prev=NULL;
return;
}

while(p1!=NULL)
{
if(p1->age>58 && p1->next!=NULL)
 {
  p1->prev->next=p1->next;
  p1->next->prev=p1->prev;
 }
 else if(p1->age>58 && p1->next==NULL)
 {
  p1->prev->next=NULL; 
 }
 p1=p1->next;
}
}

void display_dept(emp* ptr, char *dept_name)
{
if(ptr->head==NULL)
{
  printf("\nno data to display\n");
  return;
}
node* p=ptr->head;
while(p!=NULL)
{
  if(strcmp(p->dpt->name,dept_name)==0)
{
    printf("%s \t %s \t %s \t %d \t %s \t %d \t %d \t %d \n",p->ssn,p->name,p->dpt->name,p->dpt->number,p->designation, p->phone_number, p->salary, p->age);
}
  p=p->next;
}
printf("\n");
}

int main()
{
emp e1;
init(&e1);
int num,sal,ph,age,dptn;
char n[20],ssn[20],des[10],dpt_name[20];
printf("Enter number of employees: ");
scanf("%d",&num);
for(int i=0;i<num;i++)
{
  printf("\nEnter ssn :");
  scanf("%s",ssn);
  printf("Enter employee name: ");
  scanf("%s",n);
  printf("Enter department name: ");
  scanf("%s",dpt_name);
  printf("Enter department number: ");
  scanf("%d",&dptn);
  printf("Enter designation: ");
  scanf("%s",des);
  printf("Enter salary: ");
  scanf("%d",&sal);
  printf("Enter phone number: ");
  scanf("%d",&ph);
  printf("Enter age: ");
  scanf("%d",&age);
if(age<0 || age>100)
{
    printf("Enter valid age\n");
    return 0;
}
else
{
    insert_f(&e1,ssn,n,ph,des,dpt_name,age,sal,dptn);
    printf("Node inserted\n");
}
}

disp(&e1);
char dept[20];
int opt;
while(1)
{
printf("\n1. To delete records of employees with age greater than 58\n2. To find details of employees working in a department\n");
scanf("%d",&opt);
switch(opt)
{
case 1:
	delete_above_58(&e1);
	printf("(The nodes after deleting the records of employees above the age of 58)\n");
	disp(&e1);
	break;
case 2:
	printf("enter department name: ");
	scanf("%s",dept);
	printf("the details of employees working in %s department: \n");
	display_dept(&e1,dept);
	break;
default:
	exit(0);
}
}
return 0;
}
Editor is loading...