Question: Please provide a working solution. In this assignment, you are required to implement a stack-based linked list in a C file named list.h. Then code

Please provide a working solution.

In this assignment, you are required to implement a stack-based linked list in a C file named list.h. Then code in a file like main.c can include this header file (like a library) and use the linked list that is readily available. For your convenience, a coding framework is provided to you:(main.c and list.h is below) Simply decompress all files into a folder and complete them. Required functions are as follows:

(1) struct linked_list* ll_create(void): ll_create allocates and returns a pointer to a linked list. If unable to allocate the list, ll_create returns NULL. You must always check if malloc returns NULL.

(2) int ll_destroy(struct linked_list *ll): deallocates a linked list, only if it is empty. Return 1 if the linked list is destroyed, and 0 if it couldnt be destroyed.

(3) void ll_add(struct linked_list *ll, int value): inserts a value at the head of the linked list.

(4) int ll_length(struct linked_list *ll): returns the total number of values in the linked list.

(5) bool ll_remove_first(struct linked_list *ll): removes the value at the head of the linked list and returns true. If the list is empty, ll_remove_first returns false.

(6) int ll_contains(struct linked_list *ll, int value): searches the linked list from head to tail and returns the first position at which the value is found.

Note: In a list with n values, the head is position 1 and the tail is position n; therefore, if the value is in the list, ll_contains returns a logical true, the offset into the linked list. If the value is not found in the list, 0 is returned; therefore, if the value is not in the list, ll_contains returns a logical false. Most often, this will be used to determine if a node is in the linked list, and not where it is in the list, thus the optimization to have it return 0 (logical false), and a 1-indexed offset otherwise (logical true).

FILE list.h:

#ifndef LIST_H #define LIST_H

static inline struct linked_list * ll_create(void) { return NULL; }

static inline int ll_destroy(struct linked_list *ll) {

}

static inline void ll_add(struct linked_list *ll, int value) {

}

static inline int ll_length(struct linked_list *ll) { return 0; }

static inline bool ll_remove_first(struct linked_list *ll) { return NULL; }

static inline int ll_contains(struct linked_list *ll, int value) { return 0; }

#endif

------------------------------------------

FILE main.c:

#include "list.h"

int main(void) { return 0; }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!