Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please write a C program to implement a doubly linked list. please use // list/list.c // // Implementation for linked list. // // #include #include

Please write a C program to implement a doubly linked list.

please use

// list/list.c // // Implementation for linked list. // //

#include #include //#include

#include "list.h"

list.h ----------------------------------------------------------------------------------------------------------------------------

// list/list.h // // Interface definition for linked list. // //

#include

/* Defines the type of the elements in the linked list. You may change this if * you want! */ typedef int elem;

/* Defines the node structure. Each node contains its element, and points to the * next node in the list. The last element in the list should have NULL as its * next pointer. */ struct node { elem value; struct node *next; }; typedef struct node node_t;

/* Defines the list structure, which simply points to the first node in the * list. */ struct list { node_t *head; }; typedef struct list list_t;

/* Functions for allocating and freeing lists. By using only these functions, * the user should be able to allocate and free all the memory required for * this linked list library. */ list_t *list_alloc(); void list_free(list_t *l);

/* Prints the list in some format. */ void list_print(list_t *l);

/* Returns the length of the list. */ int list_length(list_t *l);

/* Methods for adding to the list. */ void list_add_to_back(list_t *l, elem value); void list_add_to_front(list_t *l, elem value); void list_add_at_index(list_t *l, elem value, int index);

/* Methods for removing from the list. Returns the removed element. */ elem list_remove_from_back(list_t *l); elem list_remove_from_front(list_t *l); elem list_remove_at_index(list_t *l, int index);

/* Checks to see if the given element exists in the list. */ bool list_is_in(list_t *l, elem value);

/* Returns the element at the given index. */ elem list_get_elem_at(list_t *l, int index);

/* Returns the index at which the given element appears. */ int list_get_index_of(list_t *l, elem value);

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

Pro SQL Server Wait Statistics

Authors: Enrico Van De Laar

1st Edition

1484211391, 9781484211397

More Books

Students also viewed these Databases questions

Question

What are blogs and how can marketers use them?

Answered: 1 week ago

Question

=+What is the nature of the plant or site-level role of unions?

Answered: 1 week ago