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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T15:48:25+00:00 2026-05-23T15:48:25+00:00

I have two vectors of XML DOM nodes: vector<IXMLDOMNodePtr> A; //filled in somehow vector<IXMLDOMNodePtr>

  • 0

I have two vectors of XML DOM nodes:

vector<IXMLDOMNodePtr> A; //filled in somehow
vector<IXMLDOMNodePtr> B; //filled in somehow

B is a subset of A. I want to remove B from A and I also want to preserve the order of A, so that if an element in A is removed it is replaced with a blank element. It would look like this:

node1||blank||node2||...

The remove_if function from <algorithm> may do the job, but i don’t know how to code the predicate function here. Does anyone know what the predicate function should look like?

update:

I tried the following code:

static MSXML2::IXMLDOMNodePtr transformIfInB(const vector<MSXML2::IXMLDOMNodePtr>& B,     MSXML2::IXMLDOMNodePtr ptr){return find(B.begin(), B.end(), ptr) != B.end() ? 0 : ptr;
}};

std::transform(vecCurRowItemSet.begin(),vecCurRowItemSet.end(),vecCurRowItemSet.begin(),std::bind1st(transformIfInB, vecTempItemSet));

vecCurRowItemSet and vecTempItemSet are all of vectors of IXMLDOMNodePtr
but i got the following errors:

c:\Program Files\Microsoft Visual Studio 10.0\VC\include\xfunctional(278): error C2825:     '_Fn2': must be a class or namespace when followed by '::'
1>          XMLDOMFromVCDlg.cpp(4161) : see reference to class template instantiation     'std::binder1st<_Fn2>' being compiled
1>          with
1>          [
1>              _Fn2=MSXML2::IXMLDOMNodePtr (const std::vector<MSXML2::IXMLDOMNodePtr>     &,MSXML2::IXMLDOMNodePtr)
1>          ]
  • 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-23T15:48:25+00:00Added an answer on May 23, 2026 at 3:48 pm

    I doubt there is a perfect algorithm for you in the standard library. The amount of work depends on whether the two vectors are pre-sorted or not, or if you can sort them.

    If you cannot sort your vectors, then you are left in O(n^2) territory, since for each element in B to be removed from A, you have to search A once over to find it.

    A good sort is O(n lg n), so pre-sorting is faster than not sorting them, in general.

    If performance is not an issue, the brute force approach is

    IXMLDOMNodePtr transformIfInB(IXMLDOMNodePtr ptr) { return find(B.begin(),B.end(), ptr) != B.end() ? 0 : ptr; }
    ...
    std::transform(A.begin(),A.end(),A.begin(),transformIfInB);
    

    If the two vectors are sorted, perhaps better to iterate through them in parallel

    typedef std::vector<IXMLDOMNodePtr>::iterator vecIt;
    vecIt itA, itB;
    std::sort(A.begin(),A.end()); 
    std::sort(B.begin(),B.end());
    for(itA = A.begin(), itB = B.begin(); itB != B.end() && itA != A.end(); )
    {
      if(*itA < *itB) ++itA; 
      else if(*itA == *itB) *itA++ == 0;
      else if(*itA > *itB ) ++itB;
    }
    

    In this loop, we hold two iterators into B and A. We move A forward while it is less than B – therefore we know there are no elements before this in A that exist in B, because they are sorted. We move B forward if the inverse is true. If they match, we zero the element per your question.

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

Sidebar

Related Questions

I have two vectors of floats and i want them to become one vector
Here's an interesting question :) I have two vectors of matrices which I want
I have two vectors: a vector and index vector. How can I make the
I have two vectors of values and one vector of weights, and I need
Currently I have two larger vectors of 50+ strings I want to be able
I have two vectors of integers, and for each element of the second vector
I have two vectors in a game. One vector is the player, one vector
I have two vectors of matching lengths. They are readings from two different sensors
I have two vectors in R of different size, and I want to add
I have two vectors and want to compare their contents (strings) but this does

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.