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

#include <iostream> #include \"2170_10_5a.h\" using namespace std; // Default Co

ID: 3554427 • Letter: #

Question

#include <iostream>
#include "2170_10_5a.h"
using namespace std;

// Default Constructor for the DummyList class
DummyList::DummyList()
{
    //create the dummy node
    head = new NodeType;
    head->next = NULL;
    head->data = -1.0;
}

// Default Destructor for the DummyList class
DummyList::~DummyList()
{
    NodePtrType q = head;
    while (q != NULL)
    {
        head = head->next;
        q->next = NULL;
        delete q;
        q = head;
    }
}

//This function inserts a node at the beginning of the list
//Add code to insert the node p at the beginning of the list.
// Remember that head is a dummy node and should never be changed.
void DummyList::InsertAtBeginning(float newData)
{
    NodePtrType p;    //pointer to node to contain new data

    //create the node
    p = new NodeType;
    //store the data
    p->data = newData;

}

//This function traverses the list and prints it.
//If the dummy head node has been altered, it prints
//and error.
void DummyList::PrintList()
{
    NodePtrType p;

    p = head;

    if (p->data != -1)
    {
        cout << "Illegal head node" << endl;
    }
    else
    {
        p = p->next;

        while (p != NULL)
        {
            cout << p->data << endl;
            p = p->next;
        }
        
        cout << endl;
    }
}

Explanation / Answer

100 % sure

Node *newListNode = new Node;

newListNode = p;

newListNode->next = head->next;

head->next = newListNode;