Question: PROBLEM: Write a method named DeleteFront for the List class that takes an integer n as input. This method should remove the first n nodes

PROBLEM: Write a method named DeleteFront for the List class that takes an integer n as input. This method should remove the first n nodes from the list. You can assume that n will always be a positive integer.

Exisiting code:

void list :: addZeros()

//Declaring temp of type node* node* temp;

//Making temp points to start node * temp = start;

//Looping through each node in linked list while(temp != NULL){

//Creating new node nn = new node;

//Assigning data to 0 nn->data = 0;

//Making next of new node to next of temp nn->next = temp->next;

//Assigning next of temp to new node nn //So, new node will be the next node from temp temp->next = nn;

//Moving to the next to next node in the linked list //So, here we get next node after the newnode that we just added to the linked list temp = nn->next; } }

void List::sumToFront()

// point temp to the head node of the list

Node temp = start;

int sum = 0;

// traverse the list

while( temp!= NULL )

{

// add the current node to sum

sum += temp->data;

// go to next node

temp = temp->next;

}

//if sum is greater than 50

if ( sum > 50)

{

temp = new node;

temp -> next = start;

start = temp;

temp ->data = sum;

}

}

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!