Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C programme : Circular list ADT You can download these 3 files in this website https://ufile.io/f/aaqbn Question 2: Circular list ADT You are going to

C programme : Circular list ADT

image text in transcribed

image text in transcribedimage text in transcribedimage text in transcribed

You can download these 3 files in this website

https://ufile.io/f/aaqbn

image text in transcribed

image text in transcribed

image text in transcribed

Question 2: Circular list ADT You are going to implement the circular list abstract data type for words using a 2-dimensional array. The header file "lab1-42.h" and the description of the functions are as follows. You can assume that each word (alphabet only) is no longer than 50 characters. The maximum size of the list is 99 (think about this). Your program should not contain main(). Name your program as lab1-q2.c". AWN HO00 - OWN - 1 1 678901234567890123 NNNNN 22 lab1-42.c x #include" lab1-42.h" 2 #include 3 #include 4 #include 5 #include 6 7 /* Initialize the circular list as an empty list #1 */ 8 /* first and last are set to 0 */ 9 E void circularlist_init_empty (CircularList **list) { 10 // Your code here 11 12 } 13 14 /* Initialize the circular list with an array of n words #2 */ 15 /* The last element of the arr is the last element in the list */ 16 /* Suppose n 3 #include #include #include 6 7 Fint main(int argc, char *argv[]) { 8 9 FILE *fout: 10 CircularList *list: 11 int isCorrect, i 12 fout = fopen(argv[i], "w"): 13 14 /* default, your program is correct */ 15 isCorrect = 1; 16 17 /* check the function, singularlist.mitmenty O */ 18 circularlist_init_empty(&list): 19 20 *if sileularlistinituents. O isn't implemented appropriately */ 21 if (list == NULL) { 22 isCorrect = 0; 23 } else if (list->first != 0 || list->last != 0) { 24 isCorrect = 0; 25 } else if (list->word[0][0] != 0 || list->word [99] [50] != 0) { 26 isCorrect = 0; 27 } 28 29 /* output "Correct if test case is passed */ 30 if (isCorrect == 1) { 31 fprintf (fout, "List: Correct "); 32 } else { 33 fprintf (fout, "List: Wrong Answer "); 34 } 35 fclose(fout): 36 37 return 0; 38 1.WN-O00 OWN POCO 001 WNHO0001 NNNNNN N Example - Question 1: Linked list ADT You are going to implement the linked list abstract data type for floating point number. The header file "lab1-91.h" and the description of the functions are as follows. Your program should not contain main(). Name your program as lab1-91.c. continue prev = tmplist : tmplist = tmplist->next; } return list /* Check if value exists in the list or not #8 */ /* If value is in the list, return 1 */ /* If value is not in the list, return 0 */ gint list_contain (Node *list, double value) { // Your code here Node *tmp for (tmp = list: tmp != NULL; tmp = tmp ->next) { = if (fabs (tmp-value - value) 3 #include 4 #include 5 #include 6 7 #define EPS 1e-4 8 9 /* Initialize the linked list as an empty list #1 */ 10 void list_init_empty (Node **list) { 11 // Your code here 12 *list = NULL; 13 } 14 15 /* Initialize the linked list with an array of n elements #2 */ 16 /* The last element of the arr is the first element in the linked list* 17 void list_init (Node **list, double *arr, int n) { 18 // Your code here 19 Node *tmplist = NULL: 20 int i 21 22 for (i = 0; inext = list: 36 37 return tmplist: 38 - } 39 40 /* Delete value from the linked list #5 #6 #7 */ 41 /* If value is in the list, then delete it */ 42 /* Note: there can be multiple value, you need to delete all of them */ 43 /* If value is not in the list, then do nothing */ 44 /* Return the head of the linked list */ 45 Node* list_delete (Node *list, double value) { 46 // Your code here 47 Node *tmplist = list, *prev = NULL; ; 48 49 while (tmplist != NULL) { 50 51 PI if (fabs (tmplist-value - value) next = ; 56 free (tmplist) 57 tmplist = list: : 58 continue 59 60 } else { 61 62 prev->next = tmplist ->next; 63 free (tmplist): 64 tmplist = prev->next; /* Free the list, if list is not NULL #9 */ /* Assign NULL to the list */ void list_free (Node **list) { // Your code here if (*list == NULL) return; list_free (&((*list)->next)): free (*list); *list = NULL; 35 111 112 113 114 115 116 117 118 119 120 121 122 /* The print function print the list in an output string #10 */ /* Example: "14.00 15.00 17.50 */ /* You can assume the number of nodes is not more than 100 */ /* You can assume the largest value is capped by 100 */ E char* list_print (Node *list) { // Your code here int maxlen = 101100: char *output - malloc(sizeof (char) *maxlen): Node *ptr = list: memset (output, 0, sizeof (char) *maxlen): for (ptr = list: ptr != NULL: ptr = ptr ->next) { sprintf (output,"%s%.2f", output, ptr-)value): } 1 53 return output 10 14 lab1-91.hx lab1-91-tc1.c X 1 // laki-al.h #include"lab1-21.h" // Cannot modify this file 2 #include 3 typedef struct _node { 3 #include double value: /* value stored in the node */ 4 #include 5 struct node * next: /* pointer to the next node */ 5 #include 6 Node 7 Fint main(int argc, char *argv[]) { 8 /* Initialize the linked list as an empty list #1 */ 8 9 void list_init_empty (Node **list): 9 FILE *fout: 10 Node *list: 11 /* Initialize the linked list with an array of n elements #2 */ 11 int isCorrect, i: 12 /* The last element of the arr is the first element in the linked list / 12 fout = fopen(argv[i], "w"): 13 void list_init (Node **list, double *arr, int n): 13 14 /* default, your program is correct */ 15 /* Insert value to the front of the linked list #3 #4 */ 15 isCorrect = 1; 16 /* Return the head of the linked list */ 16 17 Node* list_insert (Node *list, double value): 17 /* check the function, distuintent */ 18 18 list_init_empty(&list): 19 /* Delete value from the linked list #5 #6 #7 */ 19 20 /* If value is in the list, then delete it */ 20 /* if listinitent is not implemented appropriately */ 21 /* Note: there can be multiple value, you need to delete all of them */ 21 if (list != NULL) { 22 /* If value is not in the list, then do nothing */ 22 isCorrect = 0; 23 /* Return the head of the linked list */ 23 } 24 Node* list_delete (Node *list, double value): 24 25 25 /* output "Correct" if test case is passed */ 26 /* Check if value exists in the list or not #8 */ 26 if (isCorrect == 1) { 27 /* If value is in the list, return 1 */ 27 fprintf (fout, "List: Correct "): 28 /* If value is not in the list, return 0 */ 28 } else { 29 int list_contain (Node *list, double value): 29 fprintf (fout, "List: Wrong Answer "); 30 30 } 31 /* Free the list, if list is not NULL #9 */ 31 fclose(fout); 32 /* Assign NULL to the *list */ 32 33 void list_free (Node **list): 33 return 0; 34 34 35 /* The print function print the list in an output string #10 */ 36 /* Example: "14.00 15.00 17.50*/ 37 /* You can assume the number of nodes is not more than 100 */ 38 /* You can assume the largest value is capped by 100 */ 39 char* list_print (Node *list)<>

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Decisions Based On Data Analytics For Business Excellence

Authors: Bastian Weber

1st Edition

9358681683, 978-9358681680

More Books

Students also viewed these Databases questions

Question

Identify the elements that make up the employee reward package.

Answered: 1 week ago

Question

Understand the purpose, value and drawbacks of the interview.

Answered: 1 week ago