merging 2 vectors

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • joeme

    merging 2 vectors

    How would one using STL do the following tasks:

    1) merge 2 sorted vectors with dupes, result shall be sorted

    2) merge 2 sorted vectors without dupes, result shall be sorted

    3) merge 2 unsorted vectors with dupes, result does not need to be sorted

    4) merge 2 unsorted vectors without dupes, result does not need to be sorted

    By "merge" I mean inserting the second vector to the first vector.

  • James Kanze

    #2
    Re: merging 2 vectors

    On Jul 23, 4:17 am, "joeme" <jo...@iamnotat home.org.invali dwrote:
    How would one using STL do the following tasks:
    1) merge 2 sorted vectors with dupes, result shall be sorted
    2) merge 2 sorted vectors without dupes, result shall be sorted
    3) merge 2 unsorted vectors with dupes, result does not need to be sorted
    4) merge 2 unsorted vectors without dupes, result does not need to be sorted
    By "merge" I mean inserting the second vector to the first vector.
    And by dupes? (The only meaning of dupe that I know is a person
    who is easily taken in by a scam, and the dictionaries I have
    access to seem to agree. But that doesn't seem to fit here.)

    Anyway, for the sorted vectors, there's std::merge, in the
    algorithms, and for the unsorted, You'd probably have to insert
    one, then the other, into an empty vector (or copy one to create
    a new vector, then insert the other); you could also consider
    some special sort of iterator which visits both vectors, and use
    the two iterator constructor of vector, but IMHO, that would
    only be justified if you needed that sort of special iterator
    for other things as well.

    --
    James Kanze (GABI Software) email:james.kan ze@gmail.com
    Conseils en informatique orientée objet/
    Beratung in objektorientier ter Datenverarbeitu ng
    9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

    Comment

    • Marcus Kwok

      #3
      Re: merging 2 vectors

      On Jul 23, 4:02 am, James Kanze <james.ka...@gm ail.comwrote:
      On Jul 23, 4:17 am, "joeme" <jo...@iamnotat home.org.invali dwrote:
      >
      How would one using STL do the following tasks:
        1) merge 2 sorted vectors with dupes, result shall be sorted
        2) merge 2 sorted vectors without dupes, result shall be sorted
        3) merge 2 unsorted vectors with dupes, result does not need to be sorted
        4) merge 2 unsorted vectors without dupes, result does not need to be sorted
      By "merge" I mean inserting the second vector to the first vector.
      >
      And by dupes?  (The only meaning of dupe that I know is a person
      who is easily taken in by a scam, and the dictionaries I have
      access to seem to agree.  But that doesn't seem to fit here.)
      By "dupes" the OP presumably means "duplicates ".

      --
      Marcus Kwok

      Comment

      Working...