Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

please help me to implement a doubly linked list using following instructions and functions. // Doubly Linked List ( DLL ). // // // //

please help me to implement a doubly linked list using following instructions and functions.

// Doubly Linked List ( DLL ).

//

//

//

// - Implement each of the functions to create a working DLL.

// - Do not change any of the function declarations

// - (i.e. dll_t* create_dll() should not have additional arguments)

// - You should not have any 'printf' statements in your DLL functions.

// - (You may consider using these printf statements to debug, but they should be removed from your final version)

// - (You may write helper functions to help you debug your code such as print_list etc)

// ==================================================

#ifndef MYDLL_H

#define MYDLL_H

// Create a node data structure to store data within

// our DLL. In our case, we will stores 'integers'

typedef struct node{

int data;

struct node* next;

struct node* previous;

}node_t;

// Create a DLL data structure

// Our DLL holds a pointer to the first node in our DLL called head,

// and a pointer to the last node in our DLL called tail.

typedef struct DLL{

int count; // count keeps track of how many items are in the DLL.

node_t* head; // head points to the first node in our DLL.

node_t * tail; //tail points to the last node in our DLL.

}dll_t;

// Creates a DLL

// Returns a pointer to a newly created DLL.

// The DLL should be initialized with data on the heap.

// (Think about what the means in terms of memory allocation)

// The DLLs fields should also be initialized to default values.

// Returns NULL if we could not allocate memory.

dll_t* create_dll(){

// Modify the body of this function as needed.

}

// DLL Empty

// Check if the DLL is empty

// Returns 1 if true (The DLL is completely empty)

// Returns 0 if false (the DLL has at least one element enqueued)

// Returns -1 if the dll is NULL.

int dll_empty(dll_t* l){

}

// push a new item to the front of the DLL ( before the first node in the list).

// Returns 1 on success

// Returns 0 on failure ( i.e. we couldn't allocate memory for the new node)

// Returns -1 if DLL is NULL.

// (i.e. the memory allocation for a new node failed).

int dll_push_front(dll_t* l, int item){

}

// push a new item to the end of the DLL (after the last node in the list).

// Returns 1 on success

// Returns 0 on failure ( i.e. we couldn't allocate memory for the new node)

// Returns -1 if DLL is NULL.

// (i.e. the memory allocation for a new node failed).

int dll_push_back(dll_t* l, int item){

}

// Returns the first item in the DLL and also removes it from the list.

// Returns 0 on failure, i.e. there is noting to pop from the list.

// Returns a -1 if the DLL is NULL.

// Assume no negative numbers in the list or the number zero.

int dll_pop_front(dll_t* t){

}

// Returns the last item in the DLL, and also removes it from the list.

// Returns 0 on failure, i.e. there is noting to pop from the list.

// Returns a -1 if the DLL is NULL.

// Assume no negative numbers in the list or the number zero.

int dll_pop_back(dll_t* t){

}

// Inserts a new node before the node at the specified position.

// Returns 1 on success

// Retruns 0 on failure:

// * we couldn't allocate memory for the new node

// * we tried to insert at a negative location.

// * we tried to insert past the size of the list

// (inserting at the size should be equivalent as calling push_back).

// Returns -1 if the list is NULL

int dll_insert(dll_t* l, int pos, int item){

}

// Returns the item at position pos starting at 0 ( 0 being the first item )

// (does not remove the item)

// Retruns 0 on failure:

// * we tried to get at a negative location.

// * we tried to get past the size of the list

// Returns -1 if the list is NULL

// Assume no negative numbers in the list or the number zero.

int dll_get(dll_t* l, int pos){

}

// Removes the item at position pos starting at 0 ( 0 being the first item )

// Retruns 0 on failure:

// * we tried to remove at a negative location.

// * we tried to remove get past the size of the list

// Returns -1 if the list is NULL

// Assume no negative numbers in the list or the number zero.

int dll_remove(dll_t* l, int pos){

}

// DLL Size

// Queries the current size of a DLL

// Returns -1 if the DLL is NULL.

int dll_size(dll_t* t){

}

// Free DLL

// Removes a DLL and all of its elements from memory.

// This should be called before the proram terminates.

void free_dll(dll_t* t){

}

#endif

image text in transcribed
2 d mplementing a Doubly Linked List (Your TO DO ) Implement the functions provided to you in the mydilh file. Do not modify the signatures (names and arguments) of these functions just provide the implementation (ie, body of code) Unit Tests A unit test is a standalone test that checks for the correctness of a specific use case in your code. In our case, we are testing if we have a working DLL implementation Please write unit tests to test your implementation. Some example tests we might come up with include: Fill a DLL, empty the DLL, and fill the DLL again. Test each function in your DLL when the DLL is not empty Test each function in your DLL when the DLL is empty etc. There is an example test file dll_test, that you can add unit tests to or practice using to see if your implementation is correct. Compile with: gcc -g -Wall dll_test.co d11_test Run with: ./d11_test You may otherwise modify main.c with your own unit tests . . . . o

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

More Books

Students also viewed these Databases questions