QuestionQuestion

Transcribed TextTranscribed Text

Doubly linked list Doubly linked list is a list where each node in the list has two pointers, next pointing to the next node and prev pointing to the previous node. A doubly linked list looks like this in the memory. Notice that the prev pointer of the head node and next pointer of the tail node points to NULL. prev Text nead tail What to do 1. See the definition of data structures already provided in doublylinkedlist.Ir file. The main driver is also provided in main.c. You only need to implement the following two functions in doublylinkedlist.c file. Make sure you handle the edge cases properly. a. void insertHead (doublyLinkedList *listPtr, int value) Insert a new node that has value given to the head of the list. Make sure you update the head pointer contained in the doublyLinkedList structure. If this node is inserted into an empty list, you should also update the tail pointer in the doublyLinkedList structure. b. int removeTail (doublyLinkedList *listPtr); Remove the tail node from the doubly linked list and return the value it contains from the function. Remember to update the tial pointer contained in the doublyLinkedList structure. Make sure you use free to release the memory holding this node.

Solution PreviewSolution Preview

These solutions may offer step-by-step problem-solving explanations or good writing examples that include modern styles of formatting and construction of bibliographies out of text citations and references. Students may use these solutions for personal skill-building and practice. Unethical use is strictly forbidden.

#include <stdio.h>
#include <stdlib.h>
#include "doublylinkedlist.h"

void insertHead(doublyLinkedList *listPtr, int value) {
    /*
    * Insert a new node that has value given to the head of the list. Make sure you
    * update the head pointer contained in the doublyLinkedList structure. If this node
    * is inserted into an empty list, you should also update the tail pointer in the
    * doublyLinkedList structure
    */

    listNode * ln = (listNode *) malloc(sizeof (listNode));
    ln->next = listPtr->head;
    ln->prev = NULL;
    ln->value = value;
    if (listPtr->tail == NULL) {
       listPtr->tail = ln;
    } else {
       listPtr->head->prev = ln;
    }
    listPtr->head = ln;
    return;
}

int removeTail(doublyLinkedList *listPtr) {
    /**
    * Remove the tail node from the doubly linked list and return the value it contains
    * from the function. Remember to update the tial pointer contained in the
doublyLinkedList structure.
    * Make sure you use free to release the memory holding this node.
    */
    if (listPtr == NULL || listPtr->head == NULL) {
       return 0;
    }...

By purchasing this solution you'll be able to access the following files:
Solution.zip.

$28.00
for this solution

or FREE if you
register a new account!

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available C-Family Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Decision:
Upload a file
Continue without uploading

SUBMIT YOUR HOMEWORK
We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats