本文整理汇总了C++中quickSort函数的典型用法代码示例。如果您正苦于以下问题:C++ quickSort函数的具体用法?C++ quickSort怎么用?C++ quickSort使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了quickSort函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: main
int main(void){
clock_t begin, end;
double timeElapsed;
srand(time(NULL));
int numNums;
int i;
scanf("%d",&numNums);
int * A = malloc(sizeof(int)*numNums);
for (i = 0; i < numNums; i++){
A[i] = rand() % 10000000;
}
begin = clock();
quickSort(A,0,numNums+1);
end = clock();
timeElapsed = (double)(end - begin) / CLOCKS_PER_SEC;
printf("\n time: %lf\n",timeElapsed);
return 0;
}
开发者ID:mlang03,项目名称:School,代码行数:18,代码来源:quick.c
示例2: main
int main(){
int waitSort[11];
int i, input;
printf("please input numbers(end by -1):\n");
for(i = 0; i < 10; i++){
scanf("%d", &input);
if(input == -1)
break;
else
waitSort[i] = input;
}
waitSort[i] = -1;
quickSort(waitSort, 0, i-1);
for(i = 0; waitSort[i] != -1; i++){
printf("%d,", waitSort[i]);
}
printf("\n");
return 0;
}
开发者ID:baifuyou,项目名称:algorithm-studying,代码行数:19,代码来源:quickSort.c
示例3: main
int main(int argc, char **argv)
{
printf("quickSort\n");
int len,i;
int *array;
printf("input count of number:");
scanf("%d",&len);
array=(int *)malloc(sizeof(int)*len);
memset((void *)array,0,4*len);//初始化为0
printf("input numbers:");
for( i=0; i<len; i++)
{
scanf("%d",&array[i]);
}
display_array(0,len,array);
quickSort(array,0,len-1);
free(array);
return 0;
}
开发者ID:wangha43,项目名称:algrithm,代码行数:19,代码来源:quick_sort.c
示例4: main
int main() {
FILE *in = fopen("task.in", "r");
FILE *out = fopen("task.out", "w");
int len = scanLen(in);
int array[len];
for ( int i = 0; i < len; i++ ) {
fscanf(in, "%d", &array[i]);
}
fclose(in);
quickSort(array, 0, len-1);
for ( int i = 0; i < len - 1; i++ ) {
fprintf(out, "%d ", array[i]);
}
fprintf(out, "%d\n", array[len-1]);
fclose(out);
return 0;
}
开发者ID:Triplescorpio,项目名称:BC,代码行数:19,代码来源:quickSort.c
示例5: main
void main(int argc, char* argv[])
{
//input
init(S,SIZE);
//before sorted
print(S,SIZE);
//calling sort interface
quickSort(S,0,SIZE-1);
//insertSort(S,0,SIZE-1);
//after sorted
print(S,SIZE);
//pause on console
getch();
return;
}
开发者ID:zju-chaoli,项目名称:https---github.com-zju-chaoli-GIT_workspace,代码行数:19,代码来源:main.c
示例6: main
int main()
{
int a[ELEM_N];
randGenerator(a,ELEM_N,1000);
printIntarray(a,ELEM_N);
// insertionSort(a,ELEM_N);
// selectSort(a,ELEM_N);
// shellSort(a,ELEM_N);
// bubbleSort(a,ELEM_N);
quickSort(a,ELEM_N);
// heapSort(a,ELEM_N);
// radixSort(a,ELEM_N);
// countingSort(a,ELEM_N);
// mergeSort(a,ELEM_N);
printIntarray(a,ELEM_N);
return 0;
}
开发者ID:zz-mars,项目名称:zz-repo,代码行数:19,代码来源:sort_test.c
示例7: main
int main(){
long long int n,c;
struct cont * arr;
scanf("%lld",&n);
arr=(struct cont *)calloc(n,sizeof(struct cont));
c=0;
while(c<n){
scanf("%s",arr[c].name);
scanf("%lld",&arr[c].val);
c++;
}
quickSort(arr,n);
for(c=0;c<n;c++){
printf("%s\n",arr[c].name);
printf("%lld\n",arr[c].val);
}
return 0;
}
开发者ID:arnabgho,项目名称:competitive_programming,代码行数:19,代码来源:modified_quick_sort.cpp
示例8: main
/***********************主函数************************/
void main()
{
cout<<"请输入数组元素的个数(500~5000):";
cin>>numArr;
if(num==0) exit(0); //可以退出
int compCount;
for(compCount=0; compCount<numArr; compCount++) //执行比较
{
getArr();
selectionSort(compCount);
insertionSort(compCount);
bottomupSort(compCount);
mergeSort(compCount);
quickSort(compCount);
}
for(int sortMode=0; sortMode<5; sortMode++)
statistics(sortMode);
output();
}
开发者ID:Strongc,项目名称:zhangpengpeng,代码行数:20,代码来源:Sort_Al.cpp
示例9: buildPrep
static void buildPrep(const QString &destinationFile)
{
// Sort the links in the memory.
// Sort comparison operator must not depend on locale, because the dictionary file
// is the same in all systems.
QList<Link> sortedLinks(links);
quickSort(sortedLinks.begin(), sortedLinks.end(), Comparsion());
// Final file.
QFile file(destinationFile);
file.open(QIODevice::WriteOnly);
quint32 entryCount = links.size();
file.write((const char*)&entryCount, sizeof(quint32));
foreach(const Link &it, sortedLinks)
{
qint64 realOffset = it.second + sizeof(quint32) + entryCount * sizeof(qint64);
file.write((const char*)&realOffset, sizeof(qint64));
}
开发者ID:karelklic,项目名称:wikt,代码行数:19,代码来源:commandxmltoprep.cpp
示例10: minAbsSumPair2
int minAbsSumPair2(int arr[],int res[][2],int size)
{
int i=0,j=size-1,index=0,sum,min_sum=abs(arr[0]+arr[size-1]);
res[index][0]=i;
res[index][1]=j;
quickSort(arr,0,size-1);
while(i!=j)
{
sum=abs(arr[i]+arr[j]);
if(min_sum>sum)//condition for finding min_sum pair
{
res[index][0]=i;
res[index][1]=j;
min_sum=sum;
}
if(sum<0)
i++;
else
j--;
}
i=0;
j=size-1;
index=1;
while(i!=j)
{
sum=arr[i]+arr[j];
if(min_sum==abs(sum))//condition for finding min_sum pair
{
if(res[0][0]!=i||res[0][1]!=j)
{
res[index][0]=i;
res[index++][1]=j;
}
}
if(sum>0)
j--;
else
i++;
}
res[index][0]=min_sum;
return index;
}
开发者ID:coderamitamar,项目名称:myCode,代码行数:42,代码来源:minimum-absolute-sum-pair.c
示例11: main
int main(int argc, const char *argv[])
{
int array[N] = {2, 3, 8, 6, 5};
//initArray(array, N);
printArray(array, N);
printf("\nPress Enter to start sort:\n");
getchar();
//bubbleArray(array, N);
//bubbleArray2(array, N); //Wrong!!
quickSort(array, 0, N-1);
printf("\nSorted! Press Enter to print\n");
getchar();
printArray(array, N);
printf("\n");
return 0;
}
开发者ID:guozesheng,项目名称:test,代码行数:20,代码来源:bubble040901.c
示例12: uprv_sortArray
/*
* Check arguments, select an appropriate implementation,
* cast the array to char * so that array+i*itemSize works.
*/
U_CAPI void U_EXPORT2
uprv_sortArray(void *array, int32_t length, int32_t itemSize,
UComparator *cmp, const void *context,
UBool sortStable, UErrorCode *pErrorCode) {
if(pErrorCode==NULL || U_FAILURE(*pErrorCode)) {
return;
}
if((length>0 && array==NULL) || length<0 || itemSize<=0 || cmp==NULL) {
*pErrorCode=U_ILLEGAL_ARGUMENT_ERROR;
return;
}
if(length<=1) {
return;
} else if(length<MIN_QSORT || sortStable) {
insertionSort((char *)array, length, itemSize, cmp, context, pErrorCode);
} else {
quickSort((char *)array, length, itemSize, cmp, context, pErrorCode);
}
}
开发者ID:119120119,项目名称:node,代码行数:24,代码来源:uarrsort.c
示例13: main
int main(){
int array[]={5,7,8,1,6,2};
int size,i;
size=MAX;
for (i=0;i<MAX;i++){
printf("%d \t",array[i]);
}
printf("\n ");
quickSort(array,0,MAX-1);
printf("\n HUGAGAG");
for (i=0;i<MAX;i++){
printf("%d \t",array[i]);
}
getch();
return 1;
}
开发者ID:tanmaybinaykiya,项目名称:codebin,代码行数:20,代码来源:quickSort.c
示例14: sort
/**
Sort the array using the supplied compare function
function sort(compare: Function = null, direction: Number = 1): Array
Where compare is defined as:
function compare(a,b): Number
*/
PUBLIC EjsArray *ejsSortArray(Ejs *ejs, EjsArray *ap, int argc, EjsObj **argv)
{
EjsFunction *compare;
int direction;
if (ap->length <= 1) {
return ap;
}
compare = (EjsFunction*) ((argc >= 1) ? argv[0]: NULL);
if (compare == ESV(null)) {
compare = 0;
}
if (compare && !ejsIsFunction(ejs, compare)) {
ejsThrowArgError(ejs, "Compare argument is not a function");
return 0;
}
direction = (argc >= 2) ? ejsGetInt(ejs, argv[1]) : 1;
quickSort(ejs, ap, compare, direction, 0, ap->length - 1);
return ap;
}
开发者ID:leemit,项目名称:ejscript,代码行数:28,代码来源:ejsArray.c
示例15: merge
struct Interval* merge(struct Interval* intervals, int intervalsSize, int* returnSize) {
if (intervalsSize <= 1) {
(* returnSize) = intervalsSize;
return intervals;
}
quickSort(intervals, 0, intervalsSize-1);
(* returnSize) = 0;
int i;
for (i = 1 ; i < intervalsSize ; i++) {
if (intervals[i].start > intervals[(* returnSize)].end) {
(* returnSize)++;
intervals[(* returnSize)].start = intervals[i].start;
intervals[(* returnSize)].end = intervals[i].end;
} else {
intervals[(* returnSize)].end = max(intervals[(* returnSize)].end, intervals[i].end);
}
}
(* returnSize)++;
return intervals;
}
开发者ID:komea,项目名称:leetcode,代码行数:20,代码来源:056-Merge+Intervals.c
示例16: merge2into1
void merge2into1()
{
FILE *fp[2], *fp1;
char filename[5];
int l,x,j,n;
for(j=0;j<2;j++)
{
sprintf(filename,"%d",j+201);
fp[j] = fopen(filename,"r");
if(fp[j] == NULL)
{
printf("Error in opening file %d\n",j+201);
return;
}
}
fp1 = fopen("BigfileOutput","w");
for(x=0;x<32;x++)
{
int m=0,a1[2*INTEGERS]={0};
for(j=0;j<2;j++)
{
for(l=0;l<INTEGERS;l++)
{
fscanf(fp[j],"%d",&a1[m++]);
}
}
quickSort(a1,0,2*INTEGERS-1);
for(n=0;n<2*INTEGERS-1;n++)
{
fprintf(fp1,"%d\n",a1[n]);
}
}
for(j=200+1;j<=202;j++)
{
sprintf(filename,"%d",j);
remove(filename);
}
fcloseall();
}
开发者ID:yash2696,项目名称:Data-Structures-and-Algorithms-Lab,代码行数:41,代码来源:ASSG2A_B140526CS_YASH_3.c
示例17: main
int main()
{
int n,i;
int m;
scanf("%d",&n);
for(i=1;i<=n;++i)//a[0]不用
{
scanf("%d",score+i);
}
scanf("%d",&m);
quickSort(1,n);
for(i=1;i<=n;++i)
{
if(m==score[i])
{
printf("%d\n",i);
break;
}
}
return 0;
}
开发者ID:laoyang103,项目名称:acm-source,代码行数:21,代码来源:TOJ3069并列排名-手写快速排序.c
示例18: main
int main(void)
{
// input numbers
int n;
while (scanf("%d",&n) != EOF)
{
struct student s[n];
for (int i = 0; i < n; i++)
{
scanf("%s %d %d", s[i].name, &s[i].age, &s[i].grade);
}
//quick sort
quickSort(s, 0, n - 1);
// print the result
for (int i = 0; i < n; i++)
{
printf("%s %d %d\n", s[i].name, s[i].age, s[i].grade);
}
}
return 0;
}
开发者ID:liuyanfight,项目名称:CS50,代码行数:21,代码来源:2.c
示例19: main
int main(int argc, char **argv)
{
if (argc != 2) {
fprintf(stderr, "Enter length of array.\n");
return EXIT_FAILURE;
}
int length = atoi(argv[1]);
int *A = (int*)malloc(length * sizeof(int));
if (A == NULL) {
return EXIT_FAILURE;
}
randomInitialization(A, length);
printArray(A, length);
quickSort(A, 0, length - 1, length);
printArray(A, length);
free(A);
return EXIT_SUCCESS;
}
开发者ID:patnir,项目名称:CLRS,代码行数:21,代码来源:week2QuickSort.c
示例20: findSingleOccurenceNumber
int findSingleOccurenceNumber(int *A, int len)
{
if (A == NULL || len < 0)
return -1;
quickSort(A, 0, len - 1);/*sorting the array using quick sort algorithm*/
int x=A[0];
for (int i = 1; i < len; i++)
{
if (i ==(len - 1))
{
if (A[i - 1] != A[i])
x = A[i];
continue;
}
if (A[i + 1] != A[i] && A[i - 1] != A[i])/*checking the predessor and successor
the current element*/
x = A[i];
}
return x;
}
开发者ID:cherry324,项目名称:MissionRnD-C-Arrays2-Worksheet,代码行数:21,代码来源:findSingleOccurenceNumber.cpp
注:本文中的quickSort函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论