Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define ll long long
- #define ull unsigned long long
- #define uom unordered_map
- #define pb push_back
- #define yes cout<<"Yes\n"
- #define no cout<<"No\n"
- #define dot(x) fixed<<setprecision(x)
- #define wrench786 ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
- #define PI (acos(-1.0))
- #define eps 0.00001
- const int LIMIT = 10000*20;
- const int mod = 1000000007;
- using namespace std;
- int partition (int arr[], int low, int high)
- {
- int x = arr[high];
- int i = (low - 1);
- for (int j = low; j <= high - 1; j++)
- {
- if (arr[j] < x)
- {
- i++;
- swap(arr[i], arr[j]);
- }
- }
- swap(arr[i + 1], arr[high]);
- return (i + 1);
- }
- void quickSort(int arr[], int low, int high)
- {
- if (low < high)
- {
- int pi = partition(arr, low, high);
- quickSort(arr, low, pi - 1);
- quickSort(arr, pi + 1, high);
- }
- }
- int main()
- {
- int n;
- cin>>n;
- int arr[n];
- for(int i=0;i<n;i++){
- cin>>arr[i];
- }
- quickSort(arr, 0, n - 1);
- for (int i = 0; i < n; i++){
- cout << arr[i] << " ";
- }
- cout << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement