Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hi I need to make an implementation for double linked list in C. However when I try any, I get a Segmentaiton Fault error in

Hi I need to make an implementation for double linked list in C. However when I try any, I get a Segmentaiton Fault error in my terminal. Here is the skeleton code, I need to have a method that does not cause this error.

#include
#include
#include
#include "dlist.h"
// Prepend a value in front of the double list.
int dlist_prepend(struct dlist** headp, struct dlist** endp, int value)
{
// Error handling.
if (headp == NULL || endp == NULL) {
return 0;
}
if (*headp == NULL) {
// The list is empty.
assert (*endp == NULL);
*headp = (struct dlist*) malloc(sizeof(struct dlist));
(*headp)->value = value;
(*headp)->prev = NULL;
(*headp)->next = NULL;
*endp = *headp;
} else {
// Add your code here.
}
return 1;
}
// Append a value in the end of the double list.
int dlist_append(struct dlist** headp, struct dlist** endp, int value)
{
// Error handling.
if (headp == NULL || endp == NULL) {
return 0;
}
if (*headp == NULL) {
// The list is empty.
assert (*endp == NULL);
*headp = (struct dlist*) malloc(sizeof(struct dlist));
(*headp)->value = value;
(*headp)->prev = NULL;
(*headp)->next = NULL;
*endp = *headp;
} else {
// Add your code here.
}
return 0;
}

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_2

Step: 3

blur-text-image_3

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

Oracle Database Foundations Technology Fundamentals For IT Success

Authors: Bob Bryla

1st Edition

0782143725, 9780782143720

More Books

Students also viewed these Databases questions

Question

Provide examples of Dimensional Tables.

Answered: 1 week ago