Question
Linked list is a type of data structure. Each item of the list holds a data and a pointer to the next item. Head is
Linked list is a type of data structure. Each item of the list holds a data and a pointer to the next item. Head is a pointer that points to the first element. Tail is the last element of the list, which points to NULL. Linked list can be implemented using structures, consisting of some data types and a pointer.
Write a program that will create the linked list in the figure below and prints out the data in order. Make sure to include functions for insert, delete, and search. Use the following list.h file to create the linked list.
"list.h" file:
#include
typedef char DATA;
struct linked_list {
DATA d;
struct linked_list *next;
};
typedef struct linked_list ELEMENT;
typedef ELEMENT *LINK;
I've already done some of the program so far. I'll show that below but I'm struggling to finish it.
/* function to insert a node into the list */
void insert(LINK p1, LINK p2, LINK q) {
assert(p1 -> next == p2);
p1 -> next = q;
q -> next = p2;
}
/* function to delete a node from the list */
void delete(LINK p1) {
p1 -> next = p1 -> next -> next;
}
/* function to print the list */
void print_list(LINK head) {
if (head == NULL)
printf("NULL ");
/* While list not null, print each node */
else {
printf("%c --> ", head -> d);
print_list(head -> next);
}
}
data next data next data next data next 10 2 headStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started