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

  • SEARCH
  • Home
  • 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 8973223
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T18:23:52+00:00 2026-06-15T18:23:52+00:00

My function search_intersection receive a set <set<string> >& inter_section . I want get the

  • 0

My function search_intersection receive a set <set<string> >& inter_section.

I want get the intersection over all subsets in inter_section.

For example if:

inter_section = { { lion, cat } , {lion, bird}, {lion, cat, bird} }

I want:

result = { lion } 

At the moment I did this

  set<string> search_intersection(set <set<string> >& inter_section)
  {

  set <set<string> >::iterator iter_ss;

  set <string>  result;


  for (iter_ss = inter_section.begin(); iter_ss != inter_section.end(); ++iter_ss)
        {
         set_intersection(iter_ss.begin(),iter_ss.end(),
         result.begin(),result.end(),
          std::inserter(result.begin(),result.end()));
   }

    cout <<  endl;

    return result;
   }

Thanks a lot!

  • 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-06-15T18:23:54+00:00Added an answer on June 15, 2026 at 6:23 pm

    Let’s try again: (Uncompiled code)

    set<string> search_intersection(const set <set<string> > &inter_section) {
       set <string>  result;
       set <set<string> >::iterator iter = inter_section.begin ();
       if ( iter != inter_section.end ()) {
          result = *iter;
          for ( ++iter; iter != inter_section.end (); ++iter ) {
             set <string>  temp;
          // intersect *iter and result, put into temp
             set_intersection(
                iter->begin(),  iter->end (),
                result.begin(), result.end(),
                std::inserter(temp,temp.end()));
             result = temp;
             }
       }
    
       return result;
    }
    

    Note that the call to set_intersection passes the begin/end of the set pointed to by the iterator. Also, there are at least two places where const should be applied to this code.

    You can’t write the results of set_intersection into one of the inputs, either. Hence a temp variable.

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

Sidebar

Related Questions

I have an array returned by the function Search.all : => [#<Search id: 7,
I have a search function in which i am returning all the records of
After I get a specific word from form. I want to get results like
<HttpGet()> Public Function Search(<FromUri()> ByVal name As Name) As HttpResponseMessage // get params from
I've a simple search function which i Want to trigger on Enter key press,
I want to call a function from a file using href. Below is my
I have a search function that will accept a search string and send it
This recursive function ( search_Bases ) would hopefully iterate through each base class and
I have code like this: function search_keyword(){ $keyword = $this->db->escape_like_str(trim($_POST['keyword'])); $sql = ( SELECT
I have code like this: function search_keyword(){ $keyword = trim($_POST['keyword']); $search_explode = explode( ,

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.