Sektion 2. Kapitel 3
single
Challenge: Forward Iterator Traversal
Stryg for at vise menuen
Opgave
Swipe to start coding
Implement the function advance_forward that advances a given std::forward_list<int>::iterator by a specified number of steps using only forward traversal. You must not use --, std::advance, or any reverse traversal.
- Accept a
std::forward_list<int>::iteratorand an integerstepsas parameters. - Move the iterator forward by
stepsusing only++it. - Return the resulting iterator.
- Do not use
--,std::advance, or any other methods that allow reverse or random access. - If the end of the list is reached before completing all steps, return the end iterator.
Løsning
Var alt klart?
Tak for dine kommentarer!
Sektion 2. Kapitel 3
single
Spørg AI
Spørg AI
Spørg om hvad som helst eller prøv et af de foreslåede spørgsmål for at starte vores chat