n C program. /* * dataStructure.h * * Provides a data structure made of a doubly-headed singly-linked list (DHSL) * of unsorted elements (integers) in which duplicated elements are allowed. * * A DHSL list is comprised of a single header and zero or more elements. * The header contains pointers to the first and last elements in the list, * or NULL if the list is empty. The first element contains a pointer to * the next element, and so on. The last element in the list has its * "next" pointer set to NULL. * * The interface of this data structure includes several utility * functions that operate on this data structure. * * Precondition: Functions that operate on such data structure * require a valid pointer to it as their first argument. * * Do not change this dataStructure.h file. * */ /*** Data structure ***/ /* List element (node): our DHSL list is a chain of these nodes. */ typedef struct element { int val; structelement*next; } element_t; /* List header: keeps track of the first and last list elements as well as the number of elements stored in our data structure. */ typedef struct list { element_t* head; element_t* tail; unsignedint elementCount; } list_t; /*** Data structure interface ***/ /* A type for returning status codes */ typedef enum { OK, ERROR, NULL_PARAM } result_t; //dataStructure.c /* Description: Appends a new element, i.e., a node containing "newElement", * to this data structure pointed to by "list" and returns OK. * If "newElement" cannot be appended, leaves the * data structure unmodified and returns ERROR. * Returns NULL_PARAM if "list" is NULL. * Time efficiency: O(1) */ result_t list_append( list_t* list, int newElement ) { result_t result = OK; // Stubbing this function // This stub is to be removed when you have successfully implemented this function, i.e., // ***Remove this call to printf!*** printf( "Calling list_append(...): appending newElement %d to list.\n", newElement ); return result; }
Types of Linked List
A sequence of data elements connected through links is called a linked list (LL). The elements of a linked list are nodes containing data and a reference to the next node in the list. In a linked list, the elements are stored in a non-contiguous manner and the linear order in maintained by means of a pointer associated with each node in the list which is used to point to the subsequent node in the list.
Linked List
When a set of items is organized sequentially, it is termed as list. Linked list is a list whose order is given by links from one item to the next. It contains a link to the structure containing the next item so we can say that it is a completely different way to represent a list. In linked list, each structure of the list is known as node and it consists of two fields (one for containing the item and other one is for containing the next item address).
Step by step
Solved in 2 steps