
- C++ Basics
- C++ Home
- C++ Overview
- C++ Environment Setup
- C++ Basic Syntax
- C++ Comments
- C++ Data Types
- C++ Variable Types
- C++ Variable Scope
- C++ Constants/Literals
- C++ Modifier Types
- C++ Storage Classes
- C++ Operators
- C++ Loop Types
- C++ Decision Making
- C++ Functions
- C++ Numbers
- C++ Arrays
- C++ Strings
- C++ Pointers
- C++ References
- C++ Date & Time
- C++ Basic Input/Output
- C++ Data Structures
- C++ Object Oriented
- C++ Classes & Objects
- C++ Inheritance
- C++ Overloading
- C++ Polymorphism
- C++ Abstraction
- C++ Encapsulation
- C++ Interfaces
Find a partition point in array in C++
In this tutorial, we are going to find the partition point in an array where all the elements left to the partition point are small and all the elements right to the partition point are large.
Let's see the steps to solve the problem.
Initialize the array.
Iterate over the array.
Iterate from 0 to I and check each value whether it is smaller than the current value or not.
Iterate from I to n and check each value whether it is larger than the current value or not.
If the bot the conditions satisfied, then return the value.
Print the partition point.
Example
Let's see the code.
#include <bits/stdc++.h> using namespace std; int findPartitionElement(int arr[], int n) { for (int i = 0; i < n; i++) { int is_found = true; for (int j = 0; j < i; j++) { if (arr[j] >= arr[i]) { is_found = false; break; } } for (int j = i + 1; j < n; j++) { if (arr[j] <= arr[i]) { is_found = false; break; } } if (is_found) { return arr[i]; } } return -1; } int main() { int arr[] = { 4, 3, 5, 6, 7 }; cout << findPartitionElement(arr, 5) << endl; return 0; }
Output
If you execute the above code, then you will get the following result.
5
Conclusion
If you have any queries in the tutorial, mention them in the comment section.
- Related Articles
- Partition Array into Disjoint Intervals in C++
- Array Partition I in Python
- Maximum average sum partition of an array in C++
- Program to find partition array into disjoint intervals in Python
- Find a Fixed Point in an array with duplicates allowed in C++
- Partition List in C++
- Partition Labels in C++
- Partition Problem in C++
- Partition Array for Maximum Sum in Python
- Find Equal (or Middle) Point in a sorted array with duplicates in C++
- Find a Fixed Point (Value equal to index) in a given array in C++
- Equal Tree Partition in C++
- Find a Fixed Point (Value equal to index) in a given array in C++ Program
- Partition Equal Subset Sum in C++
- Minimum toggles to partition a binary array so that it has first 0s then 1s in C++

Advertisements