answersLogoWhite

0

#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

11y ago

What else can I help you with?

Continue Learning about Engineering

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.


What is the Logo command to draw alphabet k?

Starting from the centre, move forward 100 pixels, turn 180 degrees and move forward 100 pixels (returning to the centre). Then turn 120 degrees. Repeat three times. repeat 3 [fd 100 rt 180 fd 100 lt 120]


Adjusted on a helocopter to change from hovering to flying forward?

In a helocopter, to change from hovering to flying forward, you adjust the cyclic. You push it forward, which increases the pitch of the rotor at the rear, decreasing it at the front, which tilts the aircraft forward, causing it to move forward. You also adjust the collective up, to increase the overall pitch, causing the aircraft to go up, because you want to quickly gain altitude in order to have a safe margin to auto-rotate in case the engine fails.


How do you set cursor in turbo c as like word pad?

In Turbo C, you can set the cursor position using the gotoxy() function. This function takes two parameters: the x (column) and y (row) coordinates, allowing you to position the cursor anywhere on the screen similar to WordPad. For example, gotoxy(10, 5); will move the cursor to the 10th column of the 5th row. To use this function, ensure you include the conio.h header file in your program.


What is the difference between seek and append command in visual basic?

Seek will simply move to a certain position. Append will add to the very end.

Related Questions

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

True.


What is the smallest lexically and syntactically correct Karel program?

The smallest lexically and syntactically correct Karel program consists of just two commands: move(); and turnOff();. This program tells Karel to move one step forward and then turn off, which is valid as it follows the required structure of Karel programs. An even simpler version could be just turnOff();, which is also valid if Karel is already at a position where it doesn't need to move.


What is a one word substitute for search?

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


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.


What position does andriy shevchenko play in?

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


What is the first move in chess that involves the keyword "pawn"?

The first move in chess that involves the keyword &quot;pawn&quot; is moving the pawn two squares forward from its starting position.


How can ponds move in chess?

In chess, pawns can move forward one square, but they have a special ability to move two squares forward from their starting position. They capture diagonally, one square forward to the left or right. Additionally, if a pawn reaches the opposite side of the board, it can be promoted to any other piece (except a king), typically a queen.


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.


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.


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.


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.