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

#include <iostream> using std::cout; using std::cin; using std::endl; using std:

ID: 3770643 • Letter: #

Question

#include <iostream>
using std::cout;
using std::cin;
using std::endl;
using std::ostream;

struct node1 {
   int data;
   node1 * p;
   ~node1() { cout << "node with " << data << " leaving ";}
};

bool deleteBetween(node1 * & s, int low, int high) // STUDENT WRITTEN
{
   // YOU CAN MAKE THE FOLLOWING ASSUMPTIONS
// 1. - the list is not empty
// 2. - the list is sorted
// 3. - the first node in the list is smaller than low
// 4. - the last node in the list is larger than high
// 5. - the parameter low is smaller than the parameter high
// NOTE: YOUR FUNCTION SHOULD RETURN ALL DELETED MEMORY TO THE HEAP
// REQUIREMENTS:
// 1. - NO MORE THAN 3 LOOPS
// 2. - NO NESTED LOOPS

   return false; // ONLY HERE TO GET THE PROGRAM TO COMPILE
}

Explanation / Answer


if(*head_ref == NULL || del == NULL)
return;

  
if(*head_ref == del)
*head_ref = del->next;


if(del->next != NULL)
del->next->prev = del->prev;

if(del->prev != NULL)
del->prev->next = del->next;   

free(del);
del=del->next
return;