Create three database using header linked list
Student (Roll No, Name, Branch ID, CGPA)
University (University ID, University Name, University Location, Year of start)
Branch (Branch ID, University ID, Branch Name)
Implement the following modules/ sub-modules using menu driven approach:
-> Keep the Roll No, University ID and Branch ID Unique (Duplicated entry should not be allowed and prompted)
-> Students can take a University ID/ Branch ID only if it is available in the University/ Branch database.
#include <conio.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int count = 0;
struct node {
struct node* prev;
int R;
long int No;
float S;
char name[20], dept[10], D[20];
struct node* next;
} * P, *temp, *tem, *te, *temp4;
void create()
{
int R;
long int No;
float S;
char name[20], dept[10], D[20];
temp = (struct node*)malloc(sizeof(struct node));
temp->prev = NULL;
temp->next = NULL;
printf("\nEnter R, name, department,designation, salary and No of employee:\n");
scanf("%d %s %s %s %f %ld",
&R, name, dept, D,
&S, &No);
temp->R = R;
strcpy(temp->name, name);
strcpy(temp->dept, dept);
strcpy(temp->D, D);
temp->S = S;
temp->No = No;
count++;
}
void insertAtBeginning() {
if (P == NULL) {
create();
P = temp;
tem = P;
}
else {
create();
temp->next = P;
P->prev = temp;
P = temp;
}
}
void insertAtEnd() {
if (P == NULL) {
create();
P = temp;
tem = P;
}
else {
create();
tem->next = temp;
temp->prev = tem;
tem = temp;
}
}
void displayTop()
{
te = P;
if (te == NULL) {
printf("\n list is empty\n");
return;
}
printf("\n linked list elements "
"from beginning:\n");
while (te != NULL) {
printf("%d %s %s %s %f %ld\n",
te->R, te->name,
te->dept, te->D,
te->S, te->No);
te = te->next;
}
printf("number of employees=%d", count);
}
int removeEnd()
{
struct node* temp;
temp = P;
if (temp == NULL) {
printf("list is empty\n");
return 0;
}
if (temp->next == NULL) {
printf("%d %s %s %s %f %ld\n",
temp->R, temp->name,
temp->dept, temp->D,
temp->S, temp->No);
free(temp);
P = NULL;
}
else {
temp = tem;
te = tem->prev;
te->next = NULL;
printf("%d %s %s %s %f %ld\n",
temp->R, temp->name,
temp->dept, temp->D,
temp->S, temp->No);
free(temp);
tem = te;
}
count--;
return 0;
}
int deletebeg()
{
struct node* temp;
temp = P;
if (temp == NULL) {
printf("list is empty\n");
return 0;
}
if (temp->next == NULL) {
printf("%d %s %s %s %f %ld\n",
temp->R, temp->name,
temp->dept, temp->D,
temp->S, temp->No);
free(temp);
P = NULL;
}
else {
P = P->next;
P->prev = NULL;
printf("%d %s %s %s %f %ld\n",
temp->R, temp->name,
temp->dept, temp->D,
temp->S, temp->No);
free(temp);
}
count--;
return 0;
}
void EDetails() {
int ch, n, i;
P = NULL;
temp = tem = NULL;
printf("Choose an option\n");
printf("\n 1.create a DLL");
printf("\n 2.Display from start");
printf("\n 3.Insert at end");
printf("\n 4.Delete End");
printf("\n 5.Insert at top");
printf("\n 6.delete at top");
printf("\n 7.Show queue");
printf("\n 8.exit\n");
while (1) {
printf("\n Enter an option : ");
scanf("%d", &ch);
switch (ch) {
case 1:
printf("\nInput number of employees:");
scanf("%d", &n);
for (i = 0; i < n; i++)
insertAtEnd();
break;
case 2:
displayTop();
break;
case 3:
insertAtEnd();
break;
case 4:
removeEnd();
break;
case 5:
insertAtBeginning();
break;
case 6:
deletebeg();
break;
case 7:
printf("\n to show DLL as queue \n1.perform insert and deletion operation by calling insertbeg() and deleteend() respectively\n \t OR \n 2.perform insert and delete operations by calling insertend() and deletebeg() respectively\n");
break;
case 8:
exit(0);
default:
printf("Invalid option\n");
}
}
}
int main() {
EDetails();
return 0;
}
Comments
Leave a comment