Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Advances In Databases And Information Systems 14th East European Conference Adbis 2010 Novi Sad Serbia September 2010 Proceedings Lncs 6295

Authors: Barbara Catania ,Mirjana Ivanovic ,Bernhard Thalheim

2010th Edition

3642155758, 978-3642155758

More Books

Students also viewed these Databases questions