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

Write a complete function that last room on the list. (Hint: There are three sce

ID: 675150 • Letter: W

Question

Write a complete function that last room on the list. (Hint: There are three scenarios to removing the last room will accept the FirstRoom pointer by reference. The function will remove the e list is empty. In this case just print "Sorry no rooms on the list' and return from the function The list has multiple rooms. In this case you need to wor 1. Th 2· The list h se just print "Sorry no rooms on the list" and return from the function as one room. In this case the head is pointing to the room that needs to be removed. 3. The e sthas multiple rooms. In this case you need to work your way down to the last room and remove it. 3. Note: In case 2 & 3, there should be a new "end" to your list. Otherwise when other functions traverse it, it will not stop if you don't have an "end" ...aka NULL i. DRAW DIAGRAMS FOR EACH SCENARIO!!!

Explanation / Answer

struct Room
{
int roomid;
   int cap;
   int occ;
struct Room *next;
};

void deleteRoom(struct Room *head, struct Room *n)
{
// When Room to be deleted is head Room
if(head == n)
{
if(head->next == NULL)
{
printf("There is only one Room. The list can't be made empty ");
return;
}

/* Copy the data of next Room to head */
head->roomid = head->next->roomid;
       head->cap = head->next->cap;
       head->occ = head->next->occ;

// store address of next Room
n = head->next;

// Remove the link of next Room
head->next = head->next->next;

// free memory
free(n);

return;
}


// When not first Room, follow the normal deletion process

// find the previous Room
struct Room *prev = head;
while(prev->next != NULL && prev->next != n)
prev = prev->next;

// Check if Room really exists in Linked List
if(prev->next == NULL)
{
printf(" Given Room is not present in Linked List");
return;
}

// Remove Room from Linked List
prev->roomid = prev->next->roomid;
       prev->cap = prev->next->cap;
       prev->occ = prev->next->occ;

// Free memory
free(n);

return;
}

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