ProDeveloperTutorial.com

Tutorials and Programming Solutions
Menu
  • Shell Scripting
  • System Design
  • Linux System Programming
  • 4g LTE
  • Coding questions
  • C
  • C++
  • DSA
  • GIT
  • 450 DSA Cracker
  • 5G NR
  • O-RAN

CPP STL: Partitions operation algorithms

prodevelopertutorial March 28, 2020
Below are the functions that are used for partition operations:
is_partitioned [C++11] : Test whether range is partitioned
partition : Partition range in two
stable_partition : Partition range in two – stable ordering
partition_copy [C++11] : Partition range into two
partition_point [C++11] : Get partition point

#include <iostream>
#include <unordered_map>
#include <algorithm>    

//for more tutorials on C, C++, STL, DS visit www.ProDeveloperTutorial.com
using namespace std;

bool IsOdd (int i) 
{ 
    return (i%2)==1; 
    
}

int main () 
{
  std::array<int,7> foo {1,2,3,4,5,6,7};

  // print contents:
  std::cout << "foo:"; 
    for (int& x:foo) 
        std::cout << ' ' << x;
        
  if ( std::is_partitioned(foo.begin(),foo.end(),IsOdd) )
    std::cout << " (partitioned)\n";
  else
    std::cout << " (not partitioned)\n";

  // partition array:
  std::partition (foo.begin(),foo.end(),IsOdd);

  // print contents again:
  std::cout << "foo:"; 
  
  for (int& x:foo)
    std::cout << ' ' << x;
    
  if ( std::is_partitioned(foo.begin(),foo.end(),IsOdd) )
    std::cout << " (partitioned)\n";
  else
    std::cout << " (not partitioned)\n";

  return 0;
}

List Of Tutorials available in this website:

C Programming 20+ ChaptersC++ Programming 80+ Chapters
100+ Solved Coding QuestionsData Structures and Algorithms 85+ Chapters
System design 20+ ChaptersShell Scripting 12 Chapters
4g LTE 60+ ChaptersMost Frequently asked Coding questions
5G NR 50+ ChaptersLinux System Programming 20+ chapters
Share
Email
Tweet
Linkedin
Reddit
Stumble
Pinterest
Prev Article
Next Article

About The Author

prodevelopertutorial

Follow this blog to learn more about C, C++, Linux, Competitive Programming concepts, Data Structures.

ProDeveloperTutorial.com

Tutorials and Programming Solutions
Copyright © 2022 ProDeveloperTutorial.com