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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T22:43:16+00:00 2026-05-31T22:43:16+00:00

I have two types of data sets. Both are in same size. One contains

  • 0

I have two types of data sets. Both are in same size. One contains vector<int> and other contains vector<vector<double> >.
When I moving forward one element by another, I can see some duplicates from my vector<int>. So, I want to delete the duplicate element (2nd element) from the vector<int> and keep the first element further. If I erase a duplicate element, then, at the same time, I want to merge the vector<double>, of corresponding two vectors, from my vector<vector<double> > data set. Once I merged, i want to delete 2nd vector<double> as it is already added to the previous vector<double>. By doing so, I want to maintain the equal size data sets further without having duplicates in first data set and without loosing any element from my second data set.

I have implemented a simple code for that, but I think its logic is wrong. So, could you please help me to rectify this code?

vector<int> data set is assigned as my_list
vector<vector<double> > data set is assigned as mydata

For example, here is my two vectors

my_list  = {222, 208, 201, 201, 201, 206, 211, 222}
mydata = {{a1,a2,a3},{b1,b2},{c1},{d1},{e1,e2},{f1,f2},{g1},{h1,h2,h3}}

after, removing duplicate from the 1st vector and by merging corresponding vectors from 
2nd data, the final output would be like as 
my_list  = {222, 208, 201, 206, 211, 222}
mydata = {{a1,a2,a3},{b1,b2},{c1, d1, e1,e2},{f1,f2},{g1},{h1,h2,h3}}




vector<int>::iterator          no, no2;
vector<vector<double> >::iterator  itr1, itr2;
int i;

for (no=my_list.begin(), no2=my_list.begin()+1, 
        itr1=mydata.begin(), itr2=mydata.begin()+1, i=0; no != my_list.end()-1;  ){

       if (*no == *no2){ //current = next 
          no2 = my_list.erase(no2);

          //add itr2 data to itr1 vector and erase itr2
          mydata[i].insert(mydata[i].end(), (*itr2).begin(), (*itr2).end()); 
          itr2 = mydata.erase(itr2);
       }
       else{
          ++no; ++no2;
          ++itr1; ++itr2;
          ++i;
       }
}
  • 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-31T22:43:17+00:00Added an answer on May 31, 2026 at 10:43 pm

    I’d better not modify original vectors, if you don’t have any memory issues it is simpler:

    vector<int> res_my_list;
    vector<vector<double> > res_mydata;
    
    vector<int>::iterator curlist = my_list.begin(), endlist = my_list.end();
    vector<vector<double> >::iterator curdata = mydata.begin(), enddata = mydata.end();
    
    res_my_list.push_back(*curlist++);
    res_mydata.push_back(*curdata++);
    
    while(curlist != endlist)
    {
        if(res_my_list.back() == *curlist)
            res_mydata.back().insert(res_mydata.back().end(), (*curdata).begin(), (*curdata).end());
        else
        {
            res_my_list.push_back(*curlist);
            res_mydata.push_back(*curdata);
        }
        ++curlist;
        ++curdata;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Have two sets of data (two tables) for patient records, one 1999-2003, the other
I have two non-overlapping sets of types and want to make other set which
I have two functions to submit to different sets of data to the same
I have two implementations of a method, one for value types and another for
I have two sets of table that are identical. One for sales and one
I have two constructors for an objects, which use two different sets of data.
I have two sets of data which I need to join, but there is
I have two database tables, one in MYSQL and one in MSSQL. Both have
So, I have two types at the moment: const unsigned char* unencrypted_data_char; string unencrypted_data;
I have two types of users for my system, normal human users with a

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.