Question: Please help me with this project. I don't know where to start. I've included the tests.c, the makefile, linkedlist.h, and the linked_lists.c below. Makefile :
Please help me with this project. I don't know where to start. I've included the tests.c, the makefile, linkedlist.h, and the linked_lists.c below.


Makefile:
CFLAGS=-O0 -Wall -Wextra
run_tests: tests
./tests
tests: tests.o linked_list.o
tests.o: tests.c linked_list.h
linked_list.o: linked_list.c linked_list.h
.PHONY: clean debug run_tests
debug: CFLAGS += -g
debug: clean
debug: run_tests
clean:
rm -f *.o run_tests
tests.c file:
#include #include #include #include "linked_list.h" static List *list = NULL; char *test_val1 = "test_val1 data"; char *test_val2 = "test_val2 data"; char *test_val3 = "test_val3 data"; char *invalidStr = "T"; ListNode* temp = NULL; void do_test(bool test, char *success_msg, char *failure_msg) { if(test) { printf("%s ", success_msg); } else { printf("%s ", failure_msg); exit(EXIT_FAILURE); } } void test_create(void) { list = list_create(); do_test(list != NULL, "List creation succeeded", "List creation failed; list_create() returned NULL"); do_test(list->first == NULL, "list->first set to NULL on creation (as it should be)", "List creation failed; list->first was not NULL"); do_test(list->last == NULL, "list->last set to NULL on creation (as it should be)", "List creation failed; list->last was not NULL"); } void test_create_node(void) { temp = list_create_node(test_val1); do_test(temp != NULL, "Node creation succeeded", "Node creation failed; list_create_node() returned NULL"); do_test(temp->value == test_val1, "Node creation succeeded", "Node creation failed; node->value not set to passed parameter"); } void test_insert_after(void) { list_insert_after(list, list_create_node(test_val1), invalidStr); do_test(list->first->value == test_val1, "list->first set correctly after first call to list_insert_after()", "list->first set incorrectly after first call to list_insert_after()"); do_test(list->last->value == test_val1, "list->last set correctly after first call to list_insert_after()", "list->last set incorreclty after first call to list_insert_after()"); do_test(list->count == 1, "list->count set to 1 after first call to list_insert_after()", "list->count set incorreclty after first call to list_insert_after()"); } void test_insert_after2(void) { list_insert_after(list, list_create_node(test_val3), NULL); do_test(list->first->value == test_val1, "list->first set correctly after second call to list_insert_after()", "list->first set incorrectly after second call to list_insert_after()"); do_test(list->first->next->value == test_val3, "list->first->next set correctly after second call to list_insert_after()", "list->first->next set incorrectly after second call to list_insert_after()"); do_test(list->last->value == test_val3, "list->last->value set correctly after second call to list_insert_after()", "list->last->value set incorrectly after second call to list_insert_after()"); do_test(list->last->prev->value == test_val1, "list->last->prev set correctly after second call to list_insert_after()", "list->last->prev set incorrectly after second call to list_insert_after()"); do_test(list->count == 2, "list->count set correctly after second call to list_insert_after()", "list->count set incorrectly after second call to list_insert_after()"); } void test_insert_after3(void) { list_insert_after(list, list_create_node(test_val2), test_val1); do_test(list->first->value == test_val1, "list->first set correctly after third call to list_insert_after()", "list->first set incorrectly after third call to list_insert_after()"); do_test(list->first->next->value == test_val2, "list->first->next set correctly after third call to list_insert_after()", "list->first->next set incorrectly after third call to list_insert_after()"); do_test(list->first->next->next->value == test_val3, "list->first->next->next set correctly after third call to list_insert_after()", "list->first->next->next set incorrectly after third call to list_insert_after()"); do_test(list->first->next->prev->value == test_val1, "list->first->next->prev set correctly after third call to list_insert_after()", "list->first->next->prev set incorrectly after third call to list_insert_after()"); do_test(list->last->value == test_val3, "list->last set correctly after third call to list_insert_after()", "list->last set incorrectly after third call to list_insert_after()"); do_test(list->last->prev->value == test_val2, "list->last->prev set correctly after third call to list_insert_after()", "list->last->prev set incorrectly after third call to list_insert_after()"); do_test(list->count == 3, "list->count set correctly after third call to list_insert_after()", "list->count set incorrectly after third call to list_insert_after()"); } void test_getters(void) { do_test(list_count(list) == list->count, "list_count() correctly returns list->count", "list_count() does not return list->count"); do_test(list_first(list) == list->first, "list_first() correctly returns list->first", "list_first() does not return list->first"); do_test(list_last(list) == list->last, "list_last() correctly returns list->last", "list_last() does not return list->last"); do_test(list_find(list, invalidStr) == NULL, "list_find() returns NULL when called with a value not in the list", "list_find() does not return NULL when called with a value not in the list"); do_test(list_find(list, test_val2)->value == test_val2, "list_find() returns the appropriate node when called with a value present in the list", "list_find() does not correctly find the requested value's node"); } void test_remove(void) { temp = list_find(list, test_val2); do_test(list_remove_node(list, temp) == test_val2, "list_remove_node() returns the value of the deleted node", "list_remove_node() does not return the value of the deleted node"); do_test(list->first->next->value == test_val3, "list->first->next set correctly after first call to list_remove_node()", "list->first->next set incorrectly after first call to list_remove_node()"); do_test(list->last->prev->value == test_val1, "list->last->prev set correctly after first call to list_remove_node()", "list->last->prev set incorrectly after first call to list_remove_node()"); do_test(list->count == 2, "list->count set correctly after first call to list_remove_node()", "list->count set incorrectly after first call to list_remove_node()"); } void test_remove2(void) { do_test(list_remove_value(list, test_val3) == test_val3, "list_remove_node() returns the value of the deleted node (2nd call)", "list_remove_node() does not return the value of the deleted node (2nd call)"); do_test(list->first->next == NULL, "list->first set correctly after second call to list_remove_node()", "list->first set incorrectly after second call to list_remove_node()"); do_test(list->last->value == test_val1, "list->last set correctly after second call to list_remove_node()", "list->last set incorrectly after second call to list_remove_node()"); do_test(list->count == 1, "list->count set correctly after second call to list_remove_node()", "list->count set incorrectly after second call to list_remove_node()"); } void test_remove3(void) { do_test(list_remove_value(list, test_val1) == test_val1, "list_remove_node() returns the value of the deleted node (3rd call)", "list_remove_node() does not return the value of the deleted node (3rd call)"); do_test(list->first == NULL, "list->first set correctly after third call to list_remove_node()", "list->first set incorrectly after third call to list_remove_node()"); do_test(list->last == NULL, "list->last set correctly after third call to list_remove_node()", "list->last set incorrectly after third call to list_remove_node()"); do_test(list->count == 0, "list->count set correctly after third call to list_remove_node()", "list->count set incorrectly after third call to list_remove_node()"); } void test_insert_before(void) { list_insert_before(list, list_create_node(test_val3), invalidStr); do_test(list->first->value == test_val3, "list->first set correctly after first call to list_insert_before()", "list->first set incorrectly after first call to list_insert_before()"); do_test(list->last->value == test_val3, "list->last set correctly after first call to list_insert_before()", "list->last set incorrectly after first call to list_insert_before()"); do_test(list->count == 1, "list->count set correctly after first call to list_insert_before()", "list->count set incorrectly after first call to list_insert_before()"); } void test_insert_before2(void) { list_insert_before(list, list_create_node(test_val1), NULL); do_test(list->first->value == test_val1, "list->first set correctly after second call to list_insert_before()", "list->first set incorrectly after second call to list_insert_before()"); do_test(list->first->next->value == test_val3, "list->first->next set correctly after second call to list_insert_before()", "list->first->next set incorrectly after second call to list_insert_before()"); do_test(list->last->value == test_val3, "list->last set correctly after second call to list_insert_before()", "list->last set incorrectly after second call to list_insert_before()"); do_test(list->last->prev->value == test_val1, "list->last->prev set correctly after second call to list_insert_before()", "list->last->prev set incorrectly after second call to list_insert_before()"); do_test(list->count == 2, "list->count set correctly after second call to list_insert_before()", "list->count set incorrectly after second call to list_insert_before()"); } void test_insert_before3(void) { list_insert_before(list, list_create_node(test_val2), test_val3); do_test(list->first->value == test_val1, "list->first set correctly after second call to list_insert_before()", "list->first set incorrectly after second call to list_insert_before()"); do_test(list->first->next->value == test_val2, "list->first->next set correctly after second call to list_insert_before()", "list->first->next set incorrectly after second call to list_insert_before()"); do_test(list->first->next->next->value == test_val3, "list->first->next->next set correctly after second call to list_insert_before()", "list->first->next->next set incorrectly after second call to list_insert_before()"); do_test(list->first->next->prev->value == test_val1, "list->first->next->prev set correctly after second call to list_insert_before()", "list->first->next->prev set incorrectly after second call to list_insert_before()"); do_test(list->last->value == test_val3, "list->last set correctly after second call to list_insert_before()", "list->last set incorrectly after second call to list_insert_before()"); do_test(list->last->prev->value == test_val2, "list->last->prev set correctly after second call to list_insert_before()", "list->last->prev set incorrectly after second call to list_insert_before()"); do_test(list->count == 3, "list->count set correctly after second call to list_insert_before()", "list->count set incorrectly after second call to list_insert_before()"); } void test_list_clear(void) { list_clear(list); do_test(list->first == NULL, "list->first set to null after calling list_clear()", "list->first not set to null after calling list_clear()"); do_test(list->last == NULL, "list->last set to null after calling list_clear()", "list->last not set to null after calling list_clear()"); do_test(list->count == 0, "list->count set to zero after calling list_clear()", "list->count not set to zero after calling list_clear()"); } void test_list_destroy(void) { // Put things back in the list before destroying it. list_insert_before(list, list_create_node(test_val3), NULL); list_insert_before(list, list_create_node(test_val2), NULL); list_insert_before(list, list_create_node(test_val1), NULL); list = list_destroy(list); do_test(list == NULL, "list is null after calling list_destroy()", "list is not null after calling list_destroy()"); } /* void test_iterate(void) */ /* { */ /* list = list_create(); */ /* list_insert_before(list, list_create_node(test_val3), NULL); */ /* list_insert_before(list, list_create_node(test_val2), NULL); */ /* list_insert_before(list, list_create_node(test_val1), NULL); */ /* // Forwards */ /* ListNode* testcur = list->first; */ /* LIST_FOREACH(list, first, next, cur) */ /* { */ /* mu_assert(testcur == cur, "Iterator is pointing at wrong node iterating forward."); */ /* testcur = testcur->next; */ /* } */ /* return NULL; */ /* } */ /* void test_iterate_bw(void) */ /* { */ /* list = list_create(); */ /* list_insert_before(list, list_create_node(test_val3), NULL); */ /* list_insert_before(list, list_create_node(test_val2), NULL); */ /* list_insert_before(list, list_create_node(test_val1), NULL); */ /* // Backwards */ /* ListNode* testcur = list->last; */ /* LIST_FOREACH(list, last, prev, cur) */ /* { */ /* mu_assert(testcur == cur, "Iterator is pointing at wrong node iterating backward."); */ /* testcur = testcur->prev; */ /* } */ /* return NULL; */ /* } */ int main(void) { test_create(); test_create_node(); test_insert_after(); test_insert_after2(); test_insert_after3(); test_getters(); test_remove(); test_remove2(); test_remove3(); test_insert_before(); test_insert_before2(); test_insert_before3(); test_list_clear(); test_list_destroy(); /* test_iterate(); */ /* test_iterate_bw(); */ printf(" Yay, your implementation passed all the tests! "); return 0; } linked_lists.c
#include "linked_list.h" /* Just initializes the list structure (the node pointers are NULL and the count = 0. */ List *list_create(void) { } /* Just initializes a ListNode structure (the node pointers are NULL and the pointer to the data is set to payload. */ ListNode *list_create_node(void *payload) { } /* Frees any nodes in the list and then frees the list structure. */ List *list_destroy(List *list) { } /* Frees any nodes in the list but leaves the list structure. */ void list_clear(List *list) { } /* Returns the count in the list structure. */ int list_count(List *list) { } /* Returns the first node in the list. */ ListNode *list_first(List *list) { } /* Returns the last node in the list. */ ListNode *list_last(List *list) { } /* Finds a node in the list by value and returns the pointer to the node. If no matching node is found, returns NULL. */ ListNode *list_find(List* list, void* value) { } /* Inserts a node in the list after the node containing value. If no node has the passed value or if value == NULL, insert at the end of the list. */ void list_insert_after(List *list, ListNode *node, void *value) { } /* Inserts a node in the list before the node containing value. If no node has the passed value or if value == NULL, insert at the beginning of the list. */ void list_insert_before(List *list, ListNode *node, void *value) { } /* Removes the specified node from the list and frees it. The node's value is saved and returned. */ void *list_remove_node(List *list, ListNode* node) { } /* Removes the node with the specified value from the list. The node's value is saved and returned. If a node with the value is not found in the list, return NULL */ void *list_remove_value(List* list, void* value) { } static void free_nodes(List *list) { }
linkedlist.h
#ifndef __libllist_llist_h__ #define __libllist_llist_h__ #include// ----- List and list node declarations ----------------------------------- // struct ListNode; typedef struct ListNode { struct ListNode *next; struct ListNode *prev; void *value; } ListNode; typedef struct List { int count; ListNode *first; ListNode *last; } List; // ----- Function prototypes ----------------------------------------------- // /* Just initializes the List structure (the node pointers are NULL and the count = 0. */ List *list_create(); /* Just initializes a ListNode structure (the node pointers are NULL and the pointer to the data is set to payload. */ ListNode *list_create_node(void *payload); /* Frees any nodes in the list and then frees the list structure. */ List *list_destroy(List *list); /* Frees any nodes in the list but leaves the list structure. */ void list_clear(List *list); /* Returns the count in the list structure. */ int list_count(List *list); /* Returns the first node in the list. */ ListNode *list_first(List *list); /* Returns the last node in the list. */ ListNode *list_last(List *list); /* Finds a node in the list by value and returns the pointer to the node. If no matching node is found, returns NULL. */ ListNode *list_find(List *list, void *value); /* Inserts a node in the list after the node containing value. If no node has the passed value or if value == NULL, insert at the end of the list. */ void list_insert_after(List *list, ListNode *node, void *value); /* Inserts a node in the list before the node containing value. If no node has the passed value or if value == NULL, insert at the beginning of the list. */ void list_insert_before(List *list, ListNode *node, void *value); /* Removes the specified node from the list and frees it. The node's value is saved and returned. */ void *list_remove_node(List *list, ListNode *node); /* Removes the node with the specified value from the list. The node's value is saved and returned. If a node with the value is not found in the list, return NULL */ void *list_remove_value(List *list, void *value); #endif
Project 4 Linked List due: Tuesday the 14th November 2017 Overview In this project, we will exercise our understanding of structs and pointers to build a useful data st ruct ure called a linked list. We're not going to write a program to use the code. Instead, you will be working to make your code pass all of the provided tests For direction, you will be given a specification (a .h file) which will describe the behaviors your linked list must provide Submission instructions Submit only the .c and .h files that you created or fleshed out, but do not zip them You do not need to submit a Makefile for this project as the one that was provided to you will be used during grading Technical Description and Instructions In this project, you will not write a full program. Instead, you will write a generic linked list library that will be subjected to a series of tests to ensure it is working correctly. What is a Linked List? A linked list is a simple data structure comprised of nodes. Each node holds a piece of data and a connection to the node in front of it and the node behind t The list itself holds a reference to the first and last nodes in the list as well as a count of how many nodes it contains in total. The C code implementing both the list and node structures will be given to you Your Job Your job for this project is simply to implement the functions whose signat ures are declared in the 'linked_list.c file provided. Once you have done this and your implementation passes the supplied tests, you're fi ished! Things to Remember and Helpful Hints: Come to class to receive additional help, hints, and direction concerning this and future projects! Project 4 Linked List due: Tuesday the 14th November 2017 Overview In this project, we will exercise our understanding of structs and pointers to build a useful data st ruct ure called a linked list. We're not going to write a program to use the code. Instead, you will be working to make your code pass all of the provided tests For direction, you will be given a specification (a .h file) which will describe the behaviors your linked list must provide Submission instructions Submit only the .c and .h files that you created or fleshed out, but do not zip them You do not need to submit a Makefile for this project as the one that was provided to you will be used during grading Technical Description and Instructions In this project, you will not write a full program. Instead, you will write a generic linked list library that will be subjected to a series of tests to ensure it is working correctly. What is a Linked List? A linked list is a simple data structure comprised of nodes. Each node holds a piece of data and a connection to the node in front of it and the node behind t The list itself holds a reference to the first and last nodes in the list as well as a count of how many nodes it contains in total. The C code implementing both the list and node structures will be given to you Your Job Your job for this project is simply to implement the functions whose signat ures are declared in the 'linked_list.c file provided. Once you have done this and your implementation passes the supplied tests, you're fi ished! Things to Remember and Helpful Hints: Come to class to receive additional help, hints, and direction concerning this and future projects
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
