c++ - correct syntax for merge -
This question may be very stupid but I do not know how to merge two sorted vectors with std :: merge To do
I tried some code using cplusplus references.
struct t {t (int x): a (x) {} int a; }; The Bull Operator & lt; (Cost T & P, Const T & B) {Return P. A & LT; B.A. } Int main () {Vector & lt; T & gt; A, b, c, a.push_back (t (10)); A.push_back (t (20)); A.push_back (t (30)); B.push_back (t (1)); B.push_back (t (50)); Merge (a.begin (), a.end (), b.begin (), b.end (), c.begin ()); Return 0; } There is a split fault with this code.
You want to make sure that it is large, or increases:
std :: merge (a.begin (), a.end (), bb.gen (), bend (), std :: back_inserter (c)); Alternatively:
c.resize (a.size ()) + b.size ()); Std :: merge (a.begin (), a.end (), b.begin (), b.end (), c.begin ()); See this #include & lt; Algorithm & gt; #include & lt; Vector & gt; #include & lt; Iterator & gt; Struct {t (int x): a (x) {} int a; }; The Bull Operator & lt; (Cost T & P, Const T & B) {Return P. A & LT; B.A. } Int main () {std :: vector & lt; T & gt; A, b, c, a.push_back (t (10)); A.push_back (t (20)); A.push_back (t (30)); B.push_back (t (1)); B.push_back (t (50)); Std :: merge (a.begin (), a.end (), b.begin (), b.end (), std :: back_inserter (c)); Return 0; }
Comments
Post a Comment