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

I need to make the some modifications to this program. 1. Add the code to print

ID: 3634984 • Letter: I

Question

I need to make the some modifications to this program.
1. Add the code to print out the linked list as indicated in the comments in the program. (There is an outline for a PRINT function at the end of the file. Just add the while loop to it.)
2. Add the code to add a single node to the end of the list.
3. Add the code to delete a node from the list.

The .h file is this:
typedef int Element_Type;

struct LinkNode;

typedef LinkNode* Node_Ptr;

struct LinkNode
{
Element_Type data_member;
Node_Ptr link_member;
};

And the .cpp file is:

#include <iostream.h>
#include "llist.h"

using namespace std;

void PrintList(Node_Ptr Head);


/***************** Main Function Starts Here ***********/
int main() {

Node_Ptr Head;
Node_Ptr NewNode_Ptr;
Node_Ptr Curr_Ptr;
Node_Ptr Prev_Ptr;
Element_Type InValue;

/*------------Create a linked list--------------------------*/


cout << "Enter values for linked list, one per line." << endl
<< "Enter 999 to end list." << endl;

Head = new LinkNode;
cin >> Head->data_member;
Curr_Ptr = Head;

cin >> InValue;

while (InValue != 999)
{
NewNode_Ptr = new LinkNode;
NewNode_Ptr->data_member = InValue;
Curr_Ptr->link_member = NewNode_Ptr;
Curr_Ptr = NewNode_Ptr;
cin >> InValue;
} // end while

Curr_Ptr->link_member = NULL; // mark the tail

PrintList(Head); // display the list

/*------------Add a node to the linked list-------------------*/

cout << "Enter a value for a new last node: ";
cin >> InValue;

/**************** ADD CODE HERE TO ADD A NODE TO THE
END OF THE LINKED LIST *********************/


cout << endl << "The list after the addition follows:" << endl;
PrintList(Head); // display the list

/*------------Insert a node in linked list-------------------*/

cout << "Enter the value of node to insert in the list: ";
cin >> InValue;

NewNode_Ptr = new LinkNode;
NewNode_Ptr->data_member = InValue;

Prev_Ptr = NULL;
Curr_Ptr = Head;

while ( (Curr_Ptr != NULL) && (InValue > Curr_Ptr->data_member) )
{
Prev_Ptr = Curr_Ptr;
Curr_Ptr = Curr_Ptr->link_member;
}

if (Prev_Ptr == NULL)
Head = NewNode_Ptr;
else
Prev_Ptr->link_member = NewNode_Ptr;


NewNode_Ptr->link_member = Curr_Ptr;

cout << endl << "The list after the insertion follows:" << endl;
PrintList(Head); // display the list



/*------------Delete a node from linked list-------------------*/

Node_Ptr Del_Ptr;

cout << "Enter the value of a node to delete: ";
cin >> InValue;


/************ ADD CODE HERE TO DELETE A NODE ***************/


delete Del_Ptr;

cout << endl << "The list after the deletion follows:" << endl;
PrintList(Head); // display the list

return 0;
} // end main
/***********************************************************/


/*---------------------------------------------------------
* Function Name: PrintList
* Parameters: pointer to the head of a linked list
* Returns: nothing
-----------------------------------------------------------*/

void PrintList(Node_Ptr Head) {

Node_Ptr Curr_Ptr;
Curr_Ptr = Head; // this sets up a pointer to the Head

cout << endl << "The list contains the following values." << endl;

/********** ADD A LOOP HERE TO PRINT OUT THE VALUES *******/


} // end PrintList



Explanation / Answer

Dear user, //add a single node to the end of the list. add(double InValue) { if(head == NULL) head = new LinkNode(InValue); else { LinkNode *nodePtr = head; while(nodePtr->next != NULL) nodePtr = nodePtr->next; nodePtr->next = new LinkNode(InValue); } } // delete a node from the list. delete(double InValue) { LinkNode *nodePtr,*previousNodePtr; if(!head) return if(head->value == InValue) { nodePtr = head; head = head->next; delete nodePtr; } else { nodePtr = head; while(nodeptr !=NULL && nodePtr->value != InValue) { prevoiusNodePtr = nodePtr; nodePtr = nodePtr->next; } if(nodePtr) { prevoiusNodePtr->next = nodePtr->next; delete nodePtr; } } }