-
-
Save Rag0n/7656396 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <fstream>//qsort by marsharp | |
#include <iostream> | |
#include <algorithm> | |
using namespace std; | |
int a[100005]; | |
void qsort(int l,int r) | |
{ | |
int i,j,tmp=a[(r+l)/2]; | |
if(r==l)return; | |
i=l; | |
j=r; | |
while(i<=j) | |
{ | |
while(a[i]<tmp)i++; | |
while(a[j]>tmp)j--; | |
if(i<=j){swap(a[i],a[j]);i++;j--;} | |
if(i<r)qsort(i,r); | |
if(l<j)qsort(l,j); | |
} | |
} | |
int main() | |
{ | |
ifstream cin("input.txt");ofstream cout("output.txt"); | |
int i,n; | |
cin>>n; | |
for(i=0;i<n;i++) | |
cin>>a[i]; | |
qsort(0,n-1); | |
for(i=0;i<n;i++) | |
cout<<a[i]<<" "; | |
return 0; | |
} | |
#include <stdio.h> ////qsort by marsharp v1.1 | |
#include <stdlib.h> | |
#include <time.h> | |
#include <algorithm> | |
int a[1658987]; | |
void qsort(int l,int r) | |
{ | |
int i,j,tmp=a[(r+l)/2]; | |
if(r==l)return; | |
i=l; | |
j=r; | |
while(i<=j) | |
{ | |
while(a[i]<tmp)i++; | |
while(a[j]>tmp)j--; | |
if(i<=j){std::swap(a[i],a[j]);i++;j--;} | |
} | |
if(i<r)qsort(i,r); | |
if(l<j)qsort(l,j); | |
} | |
int main() | |
{ | |
int i,n; | |
printf("Enter N: "); | |
scanf("%d",&n); | |
// int *a=new int[n]; | |
srand (time(NULL)); | |
for(i=0;i<n;i++) | |
a[i]=rand()%100; | |
printf("Generated array: \n"); | |
for(i=0;i<n;i++) | |
printf("%d ",a[i]); | |
printf("\n"); | |
qsort(0,n-1); | |
printf("Sorted array: \n"); | |
for(i=0;i<n;i++) | |
printf("%d ",a[i]); | |
printf("\n"); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment