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 6339291
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T19:37:24+00:00 2026-05-24T19:37:24+00:00

I have four group of data: //group 1 2 2 6 2 2 7

  • 0

I have four group of data:

//group 1
2 2 6
2 2 7
2 3 5
2 3 6
2 3 7

3 2 5
3 2 6
3 2 7
3 3 4
3 3 5
3 3 6
3 3 7
...
...
7 2 2
7 2 3
7 2 5
7 2 7
7 3 2
7 5 2
7 6 2

//group 2
2 2 2
2 2 3
2 2 4
2 2 5
2 3 2
2 3 3

3 3 2
3 3 3
3 4 2
...
...

5 2 2

//group 3
2 4
2 5

3 3
3 4
3 5
3 6
...
...
7 2

//group 4
6
7
8

And what I want to do is for given input number(s), give all the possible results.
A example might help to explain what I want to do:
Say input is 7, then the output should be the following:

from group 1
7 2 2
7 2 3
7 2 5
7 2 7
7 3 2
7 5 2
7 6 2

from group 2
//nothing

from group 3
7 2

from group 4
7

Then I add second input 2 (so the total input is 7 2), then the result should be

from group 1
7 2 2
7 2 3
7 2 5
7 2 7

from group 2
//nothing

from group 3
7 2

from group 4
//nothing

Then I add a 3rd input 5 (so the total input is 7 2 5), then the result should be

from group 1
7 2 5

from group 2
//nothing

from group 3
//nothing

from group 4
//nothing

It appears to be I need a forest(several trees) for this, correct ?
If so , is there any good c++ tree implementation of forest for this task or I better hand made one myself ?

Many Thanks

  • 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-24T19:37:25+00:00Added an answer on May 24, 2026 at 7:37 pm

    Something like to hold the data

    std::set<std::vector<int> > data;
    

    Now you can create one of these for each group if there is no guarantee that the number of items in each group is the same, or if you know what each group is a specific number of items, then put them all in the same set.

    Then use std::find_if with a custom predicate with the above data. And in this predicate have a std::vector which is the sequence you are looking for.

    struct search_sequence
    {
      bool operator()(std::vector<int> const& cVal) const
      {
        if (sequence.size() <= cVal.size())
          return std::equal(sequence.begin(), sequence.end(), cVal.begin());
        return false;
      }
    
      std::vector<int> sequence;
    };
    

    Now applying this with std::find_if will find all sequences in data which start with the search sequence.

    EDIT: To store in the single instance, wrap the vector, e.g.

    struct group_entry
    {
      int id;
      std::vector<int> data;
    
      friend bool operator<(group_entry const& lhs, group_entry const& rhs)
      {
        return lhs.id < rhs.id && lhs.data < rhs.data;
      }
    };
    

    Now your set contains

    std::set<group_entry> data;
    

    Add all the data from all the groups

    Modify the predicate:

    struct search_sequence
    {
      bool operator()(group_entry const& cVal) const
      {
        if (sequence.size() <= cVal.data.size())
          return std::equal(sequence.begin(), sequence.end(), cVal.data.begin());
        return false;
      }
    
      std::vector<int> sequence;
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have four tables I want to join and get data from. The tables
i have four radio buttons , and i want to set a text for
I have a table of four columns. The data in the first column is
i have a table named item with four attribute name,code,class,value now i want to
I have a table with data : id one two three four five six
I have a report in SSRS 2008 that shows data aggregated from four levels
I have a data structure as such: <rootnode> <group> <id>1</id> <anothernode>first string</anothernode> <anothernode>second string</anothernode>
I have a semi-melted data frame that looks like this: head(final_melt) Group Source variable
I have a report where I need the same data, but for four separate
Please help. I'm using MySQL 5.1.30 Community Edition. I have four tables: nts, operator,

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.