/***
Md. Namzul Hasan
Shahjalal University of Science & Technology,Sylhet.
hasan08sust@gmail.com
***/
#include<bits/stdc++.h>
using namespace std ;
typedef long long ll ;
typedef int in ;
typedef unsigned long long ull ;
const double pi = 2*acos(0) ;
#define maxi 40000
#define pf printf
#define sc scanf
#define pb push_back
#define MEM(x,y) (memset((x),(y),sizeof(x)))
#define MIN(x,y) ((x) < (y) ? (x) : (y))
#define MAX(x,y) ((x) > (y) ? (x) : (y))
#define load(array,size) for(int i=0 ; i<size ; i++) cin>>array[i] ;
#define new_line pf("\n")
vector<int> data ;
void quick_sort(int left, int right)
{
int i = left ;
int j =right ;
int temp ;
int pivot = data[(left+right)/2] ;
while(i<=j)
{
while(data[i]<pivot)
i++ ;
while(data[j]>pivot)
j-- ;
if(i<=j)
{
swap(data[i],data[j]) ;
i++ ;
j-- ;
}
}
if(left<j)
{
quick_sort(left,j) ;
}
if(i<right)
quick_sort(i,right) ;
}
int main()
{
int n,p ;
cin>>n ;
for(int i=1 ; i<=n ; i++)
{
cin>>p ;
data.pb(p) ;
}
int a,b ;
a =0 ;
b = data.size()-1 ;
quick_sort(a,b) ;
for(int i=0 ; i<data.size(); i++)
pf("%d ",data[i]) ;
return 0;
}
Md. Namzul Hasan
Shahjalal University of Science & Technology,Sylhet.
hasan08sust@gmail.com
***/
#include<bits/stdc++.h>
using namespace std ;
typedef long long ll ;
typedef int in ;
typedef unsigned long long ull ;
const double pi = 2*acos(0) ;
#define maxi 40000
#define pf printf
#define sc scanf
#define pb push_back
#define MEM(x,y) (memset((x),(y),sizeof(x)))
#define MIN(x,y) ((x) < (y) ? (x) : (y))
#define MAX(x,y) ((x) > (y) ? (x) : (y))
#define load(array,size) for(int i=0 ; i<size ; i++) cin>>array[i] ;
#define new_line pf("\n")
vector<int> data ;
void quick_sort(int left, int right)
{
int i = left ;
int j =right ;
int temp ;
int pivot = data[(left+right)/2] ;
while(i<=j)
{
while(data[i]<pivot)
i++ ;
while(data[j]>pivot)
j-- ;
if(i<=j)
{
swap(data[i],data[j]) ;
i++ ;
j-- ;
}
}
if(left<j)
{
quick_sort(left,j) ;
}
if(i<right)
quick_sort(i,right) ;
}
int main()
{
int n,p ;
cin>>n ;
for(int i=1 ; i<=n ; i++)
{
cin>>p ;
data.pb(p) ;
}
int a,b ;
a =0 ;
b = data.size()-1 ;
quick_sort(a,b) ;
for(int i=0 ; i<data.size(); i++)
pf("%d ",data[i]) ;
return 0;
}
No comments:
Post a Comment