Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Below is a depiction of a doubly-linked list implementation of the bag ADT with

ID: 3666096 • Letter: B

Question

Below is a depiction of a doubly-linked list implementation of the bag ADT with two sentinels –one at the head and one at the tail.

Struct DLink

{

TYPE value;

struct DLink * next;

struct DLink * prev;

};

struct linkedList

{

int size;

struct DLink *frontSentinel;

struct DLink *backSentinel;

};

Write a function that swaps the first occurrence of the specified value (passed as parameter) with the value of the first node of the collection. Don’t redirect to any other function.  

backSentinel Linked List frontSentinel

Explanation / Answer

This below function will find the first occurence of element in double linked list without altering the links between the nodes..once the element is find in the list and will replace with first node element in the current list..

See the below function called

void GetElement(struct linkedList* head, int element)
{
struct linkedList* current = head;  

struct linkedList* present = head;
/* the element of the node we're currently looking at */
while (current != NULL)
{
if (current->size == element)
   {
current->size = present ->size;
}
current = current->next;
}

/* if we get to this line, the caller was asking
for a non-existent element so we assert fail */
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote