answersLogoWhite

0


Best Answer

#include<iostream>

#include<forward_list>

void print (std::forward_list<unsigned>& list)

{

for (std::forward_list<unsigned>::iterator i=list.begin(); i!=list.end(); ++i)

std::cout << *i << '\t';

std::cout << std::endl;

}

bool insert (std::forward_list<unsigned>& list, unsigned value, unsigned position)

{

// there is no 0th position

if (position list.end())

return false;

// i is the nth-1 node

list.insert_after (i, value);

return true;

}

bool move (std::forward_list<unsigned>& list, unsigned value, unsigned position)

{

list.remove (value);

return (insert (list, value, position));

}

int main()

{

// initialise a forward list with 9 unique values 1, 2, 3, ..., 8, 9

std::forward_list<unsigned> list;

for (unsigned i=1; i<=10; ++i)

insert (list, i, i);

std::cout << "initial list\n" << std::endl;

print (list );

// insert the value 11 at the 6th position in the list

insert (list, 11 , 6);

std::cout << "\nafter inserting the value 11 at position 6\n" << std::endl;

print (list);

// move the value 11 to position 11 in the list

move (list, 11, 11);

std::cout << "\nafter moving the value 11 to position 11\n" << std::endl;

print (list);

}

User Avatar

Wiki User

10y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Write a C plus plus program to move a node to nth position in forward?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

A forward and downward move from the normal anatomical position is known as lordosis?

True.


What is a one word substitute for search?

because i need a change and move forward with a new position.


What position does andriy shevchenko play in?

Andrliy Shevchenko plays in Chelsea but he might move to FC Moscow, he is a forward player.


Why does your car move forward when in neutral?

The neutral position puts a cars transmission out of gear and therefore makes the car roll.


How can you get the drivers power seat to move forward or backward to a desired position?

Take initiatives, take actions or call for taking an action.


What is an appropriate answer during an interview if you resigned a position because your boss was a bully?

I have a challenging boss and I make my decision to move forward with my life.


To move closer to something?

Simply take a step forward in the direction of the object you want to move closer to. Alternatively, you can physically move your body or adjust your position until you reach the desired distance from the object.


How does a bulldozer work?

A bulldozer is powered by a massive diesel engine that propels it forward. The engine also powers the hydraulics that move the blade into the position needed to move earth and rubble.


Does 'pulling out' mean motion forward motion backwards or either?

The term 'pulling out' means to move off from a stopped position and join the flow of traffic. This would generally mean moving forward.


What is something that always moves forward?

A bookperson. Time doesn't move forward. Time is. People move forward or regress. Bookpeople learn, grow and always move forward.


To move forward in position or authority?

To advance in position or authority, one must demonstrate leadership abilities, take on additional responsibilities, and deliver results consistently. Building strong relationships with colleagues and supervisors, seeking growth opportunities, and continuously improving skills are important steps to move forward in position or authority. Additionally, showing dedication, initiative, and a willingness to learn can help pave the way for career progression.


What does resurgamus mean?

Resurgamus means 'to move forward'. Resurgamus means 'to move forward'.