Search
 
SCRIPT & CODE EXAMPLE
 

CPP

partition in STL using vector

// C++ code to demonstrate the working of
// partition() and is_partitioned()
#include<iostream>
#include<algorithm> // for partition algorithm
#include<vector> // for vector
using namespace std;
int main()
{
    // Initializing vector
    vector<int> vect = { 2, 1, 5, 6, 8, 7 };
     
    // Checking if vector is partitioned
    // using is_partitioned()
    is_partitioned(vect.begin(), vect.end(), [](int x)
    {
        return x%2==0;
         
    })?
     
    cout << "Vector is partitioned":
    cout << "Vector is not partitioned";
    cout << endl;
     
    // partitioning vector using partition()
    partition(vect.begin(), vect.end(), [](int x)
    {
        return x%2==0;
         
    });
     
    // Checking if vector is partitioned
    // using is_partitioned()
    is_partitioned(vect.begin(), vect.end(), [](int x)
    {
        return x%2==0;
         
    })?
     
    cout << "Now, vector is partitioned after partition operation":
    cout << "Vector is still not partitioned after partition operation";
    cout << endl;
     
    // Displaying partitioned Vector
    cout << "The partitioned vector is : ";
    for (int &x : vect) cout << x << " ";
     
    return 0;
     
}
Comment

PREVIOUS NEXT
Code Example
Cpp :: 1047. Remove All Adjacent Duplicates In String solution leetcode in c++ 
Cpp :: c++ to c converter online 
Cpp :: return value from a thread 
Cpp :: ue4 array copy c++ 
Cpp :: run a c++ file in terminal 
Cpp :: How to clear keyboard buffer c++ 
Cpp :: c++ starting syntaz 
Cpp :: ala vida 
Cpp :: play sound opencv video c++ 
Cpp :: simplest code for stack implementation in c++ 
Cpp :: https://www.geeksforgeeks.org/a-program-to-check-if-strings-are-rotations-of-each-other/ 
Cpp :: left recursion program in c++ 
Cpp :: how to list directory in c++ 
Cpp :: gcd 
Cpp :: how to use printf with microseconds c++ 
Cpp :: wap in c++ to understand function template 
Cpp :: Change Font ImGui 
Cpp :: _ZNSolsEi 
Cpp :: tutti i tipi di equazioni trigonometriche 
Cpp :: c++ suare 
Cpp :: opengl triangle example 
Cpp :: converter c++ to c 
Cpp :: c++ cin string 
Cpp :: math in section latex 
Cpp :: c++ function with parameters 
Cpp :: c++ switch case statement 
C :: c check if file exists 
C :: como programar a area de um triangulo em c 
C :: curl authorization header 
C :: sigaction in c 
ADD CONTENT
Topic
Content
Source link
Name
2+8 =