|
| vector< int > | pivotArray (vector< int > &nums, int pivot) |
| |
Definition at line 5 of file main.cpp.
◆ pivotArray()
| vector< int > Solution::pivotArray |
( |
vector< int > & |
nums, |
|
|
int |
pivot |
|
) |
| |
|
inline |
Definition at line 8 of file main.cpp.
9 {
10 queue<int> left;
11 queue<int> right;
12 int pivot_count = 0;
13 for (int i = 0; i < (int)nums.size(); ++i)
14 {
15 if (nums[i] < pivot)
16 left.push(nums[i]);
17 else if (nums[i] > pivot)
18 right.push(nums[i]);
19 else
20 pivot_count++;
21 }
22 vector<int> answer;
23 answer.reserve(nums.size());
24 while (!left.empty())
25 {
26 answer.push_back(left.front());
27 left.pop();
28 }
29 for (int i = 0; i < pivot_count; ++i)
30 answer.push_back(pivot);
31 while (!right.empty())
32 {
33 answer.push_back(right.front());
34 right.pop();
35 }
36 return answer;
37 }
Referenced by main().
The documentation for this class was generated from the following file: