Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7047681
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T02:48:02+00:00 2026-05-28T02:48:02+00:00

In forward_list there is a function splice_after ( for reference ), specifically, function #3

  • 0

In forward_list there is a function splice_after (for reference), specifically, function #3 in the link given. How would one go about implementing that considering the list is singly linked.

As an exercise, when I implemented it, I had to iterate the list until I reached the node before first (so that I can connect first to last) and again until I reached the node before last (so that I can connect the current list’s node to the node before last). This does not seem terrible efficient to me and was wondering whether there is a better way to do it without iteration?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T02:48:03+00:00Added an answer on May 28, 2026 at 2:48 am

    I suspect you misread the somewhat subtle range specification which says that “(first, last)” is moved, not “[first, last)” (note the opening parenthesis/bracket). That is, as the name indicates, the splice operation only starts after the first object.

    The implementation of the function is actually quite simple (if you ignore constness of the iterators and the fact that it might need to deal with allocators being different):

    void splice_after(const_iterator pos, forward_list& other,
                      const_iterator first, const_iterator last) {
        node* f = first._Node->_Next;
        node* p = f;
        while (p->_Next != last._Node) { // last is not included: find its predecessor
            p = p->_Next;
        }
        first._Node->Next = last._Node;  // remove nodes from this
        p->_Next = pos._Node->_Next;     // hook the tail of the other list onto last
        pos._Node->_Next = f;            // hook the spliced elements onto pos
    }
    

    This operation has linear complexity because it needs to find the predecessor of last.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a tool that would go through a list of files and would
I read some interview question online about how would you find if there's a
I'm currently using the anythingSlider it works quite well. But if there is one
So, Erlang is a real joy to work with, but there's one problem I
I've created almost the same plugin as JobTypeColumn. There is only one difference -
The basic idea of the program is that it searches a large list for
In my c# app, I've got a list that I navigate with an Enumerator.
There is a declaration of template class with implicit parameters: List.h template <typename Item,
So far I've got scrolling list items on click using the code below: $('li#news-back').click(function(){
Is there a language construct in C# that allows the abstraction of loop (or

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.