sorting vectors into 3 categories

i need to sort the elements i have into 3 other vectors
the program will prompt the user for a number
the elements in vectdata that is smaller than the number provided by the user must be put into another vector,vectsmall
same for vectlarge(elements larger than number) and vectsame(elements that are same as number)

create three new vectors: smaller, same, larger

for each element in original vector:
if element is smaller than USER_INPUT_VALUE
{ copy into vector smaller }
else if element is same as USER_INPUT_VALUE
{ copy into vector same}
else
{ copy into vector larger }
Thank you
Yes I have created 3 separate vectors

So would it look something like
for (auto c: vectdata)
If (c<user input number)
Vectsmall.push_back(c)

And the same for large(>) and same(=)
same(==)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include <iostream>
#include <vector>
using namespace std;


void write( vector<int> V )
{
   for ( int i : V  ) cout << i << ' ';
   cout << '\n';
}


int main()
{
   vector<int> myData = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
   vector<int> smaller, same, larger;
   vector<int> *p[] = { &smaller, &same, &larger };
   
   int value = 3;

   for ( int i : myData ) (*p[ (i >= value) + (i > value) ]).push_back( i );

   write( smaller );
   write( same    );
   write( larger  );
}
0 1 2 
3 
4 5 6 7 8 9 


Thank you so much
For same I figured the error when I put = instead of ==
Thanks anyway
Topic archived. No new replies allowed.