Perform each of the following: floorLg(n)= { 0 for n = 1 1 + floorLg(n/2) for n>
ID: 3562978 • Letter: P
Question
Perform each of the following:
floorLg(n)= { 0 for n = 1 1 + floorLg(n/2) for n>1Explanation / Answer
#include #include #include #define NAME_LENGTH 20 typedef struct employeeData { int EMP_ID; char* Name; int Dept; int Rank; double Salary; struct employeeData *next; }employee; employee* InitializeList(int EMP_ID, char* Name, int Dept, int Rank, double Salary) { employee* ptr = (employee*)(malloc(sizeof(struct employeeData))); ptr->Name = (char*)malloc(sizeof(char)*NAME_LENGTH); strcpy(ptr->Name, Name); ptr->EMP_ID = EMP_ID; ptr->Dept = Dept; ptr->Rank = Rank; ptr->Salary = Salary; ptr->next = NULL; return ptr; } employee* insert_by_employee(employee* head, employee* ptr) { employee* current = NULL; current = head; if(current == NULL || strcmp(current->Name, ptr->Name) > 0) { ptr->next = current; return ptr; } else { while(current->next != NULL && strcmp(current->next->Name, ptr->Name) < 0) { current = current->next; } } ptr->next = current->next; current->next = ptr; return head; } void query(employee *head, int submenu) { printf(" Emp name "); employee* current; current = head; while (current != NULL) { if(current->Rank == submenu) { printf("%s ", current->Name); current = current->next; } current = current->next; } return; } void printlist(employee* head) { employee* current; current = head; printf("EMP_ID EMP NAME DEPT RANK SALARY "); while ( current != NULL) { printf(" %d %s %d %d %d ", current->EMP_ID, current->Name, current->Dept, current->Rank, current->Salary); current = current->next; } return; } int main(void) { FILE* ifp = fopen("empInfo.txt", "r"); int EMP_ID, Dept, Rank, menu_choice = -1, submenu; double Salary; char* Name = (char*)malloc(sizeof(char*)*NAME_LENGTH); employee *head = NULL; while(!feof(ifp)) { fscanf(ifp, "%d %s %d %d %d", &EMP_ID, Name, &Dept, &Rank, &Salary); { if (EMP_ID == 0) break; } employee* hold = InitializeList(EMP_ID, Name, Dept, Rank, Salary); head = insert_by_employee(head, hold); } while (menu_choice != 0) { printf(" Please select an action from the following menu "); printf("1 to add a new employee "); printf("2 to delete an employee "); printf("3 to modify an employee record "); printf("4 to query employees by rank "); printf("5 to print all employee information "); printf("0 (or any other number) to stop "); scanf("%d", &menu_choice); if(menu_choice == 1) { printf("choice 1 "); menu_choice = -1; } if (menu_choice == 2) { printf("Choice 2 "); menu_choice = -1; } if (menu_choice == 3) { printf("Choice 3 "); menu_choice = -1; } if (menu_choice == 4) { printf("Please provide rank that you would like to query. "); scanf("%d", &submenu); query(head, submenu); menu_choice = -1; } if (menu_choice == 5) { printlist(head); menu_choice = -1; } } fclose(ifp); return 0; }Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.