Cyat Learning... Starfall Education. The YouTube Kids... As we discussed, doubly linked lists are more complex than sing

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

Cyat Learning... Starfall Education. The YouTube Kids... As we discussed, doubly linked lists are more complex than sing

Post by answerhappygod »

Cyat Learning Starfall Education The Youtube Kids As We Discussed Doubly Linked Lists Are More Complex Than Sing 1
Cyat Learning Starfall Education The Youtube Kids As We Discussed Doubly Linked Lists Are More Complex Than Sing 1 (73.21 KiB) Viewed 42 times
Cyat Learning Starfall Education The Youtube Kids As We Discussed Doubly Linked Lists Are More Complex Than Sing 2
Cyat Learning Starfall Education The Youtube Kids As We Discussed Doubly Linked Lists Are More Complex Than Sing 2 (46.22 KiB) Viewed 42 times
Hello!
In this assignment, the functions on line 18, 38, and 50 must be
re-written and able to produce the output in the first
picture.
DO NOT CHANGE ANYTHING AFTER LINE 67 AS THE FUNCTIONS THAT ARE
GOING TO BE RE-WRITTEN HAVE TO WORK WITH THOSE AFTER LINE 67 TO
PRODUCE THAT OUTPUT.
thank you!
Cyat Learning... Starfall Education. The YouTube Kids... As we discussed, doubly linked lists are more complex than singly linked lists, but they are more powerful and easier to use because they have the following attributes: " Reading . New items can be added to either the beginning or the end without cycling through the list . New items can be easily added before or after any arbitrary item already in the list. .Items can be removed without needing to know the address of the list head • Items can be removed from either the beginning or the end without cycling through the list Your task is to simply use the provided linked list implementation to load a csv (comma separated values) file into a linked list. You will find this csv file in the provided project workspace. Each line of the csv file has the following format: name, age, salary, years For each such line in the csv file, you should allocate a struct, populate the struct with the data for the line in the csv file, and add the struct to the linked list. I gave an example of working with csv files in Lecture 7. Watch the review video if you are having trouble [here]. In addition to loading the csv file into a linked list, you must also write functions for: searching the linked list for a particular person by name . properly unloading the linked list and removing it from memory Read the comments in the provided source code for details regarding the behavior of the function definitions you must write for this assignment. EXAMPLE OUTPUT $ gcc -o HW8 main.c list.c $ ./HW8 Usage: /HW8 employee_name $ ./HW8 Thorsten Employee Thorsten: Age: 40 Salary: 87440.95 Years: 19
1 #include 2 #include 3 #include 4 #include "list.h" 5 6 #define to person(ptr) \ 6700 container_of(ptr, struct person, node) 8 9▼ struct person { 10 char name[128]; 11 int age; 12 int salary; 13 int years; 14 struct list node; 15 }; 16 17 18▼ /* This function must do the following: 19 * 1. Open the provided filename 20 * 2. Return The NULL Pointer if filename could not be opened 21 * 3. Allocate a new list head on the heap 22 * 4. Populate the list with data from the file 23 * 5. Return the head of the populated list */ 24 struct list *load_database (const char *filename) 25 ▼ { 26 FILE *fp; 27 fp = fopen(filename, "r"); 28 29 struct list *head; 30 struct person *item; 31 32 /* Rewrite this function! */ 33 34 return NULL; 35 } 36 37
38▼ /* This function must do the following: 39 * 1. Remove all items from the provided list 40 * 2. Free each removed item from the heap */ 41 void unload_database(struct list *head) 42 ▼ { 43 struct list *cur, *sav; struct person *item; 44 45 46 /* Your code goes here! */ 47 } 48 49 50 /* This function must do the following: 51 * 1. Search the provided list for the item having the provided name 52 * 2. Return the item if found 53 * 3. Return The NULL Pointer if not found */ 54 struct person *find_person(struct list *head, const char *name) 55 ▼ { 56 struct list *cur; 57 struct person *item; 58 /* Rewrite this function! */ return NULL; 28 3295 60 61 62 63 64
65} 66 67 /* This function prints the provided struct person to the screen */ 68 void print_person(struct person *p) 69 ▼ { 70 printf("Employee %s:\n", p->name); 71 printf(" Age: %d\n", p->age); 72 printf("Salary: $ %0.2f\n", (float)p->salary / 100.0f); 73 printf(" Years: %d\n", p->years); 74 } 75 76 77 int main(int argc, char **argv) 78 ▼ { 79 struct list *head; 80 struct person *item; 81 82 ▼ if (argc != 2) { 83 fprintf(stderr, "Usage: %s employee_name\n", argv[0]); return EXIT_FAILURE; 84 85 } 86 87 head = load_database ("employees.csv"); 88 89 ▼ if (!head) { 90 fprintf(stderr, "Failed to open database.\n"); return EXIT_FAILURE; 91 92 } 93 94 item = find_person(head, argv[1]); 95 if (item) 96 print_person(item); 97 else 98 printf("Employee NOT FOUND!\n"); 99 100 unload_database (head); 101 free(head); 102 103 return 0; 104 }
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply