-
March 14th, 2011, 10:01 PM
#1
help me please
#include<windows.h>
#include<algorithm>
#include<iostream>
#include<ctime>
#include<ppl.h>
using namespace Concurrency;
using namespace std;
const size_t size = 1024;
template <class T>
int split(T* items,int lower,int upper)
{
int i,p,q,t;
p = lower+1;
q = upper;
i = items[lower];
while(q>=p){
while(items[p]<i) p++;
while(items[q]>i) q--;
if(q>p)
{
t = items[p];
items[p] = items[q];
items[q] = t;
}
}
t = items[lower];
items[lower] = items[q];
items[q] = t;
return q;
}
template <class T>
void quicksort(T* items,int lower,int upper)
{
int pivot;
if(upper>lower)
{
pivot = split(items, lower, upper);
parallel_invoke(
[&items,lower,upper,pivot] { quicksort(items, lower, pivot-1); },
[&items,lower,upper,pivot] { quicksort(items, pivot+1 ,upper); }
);
}
}
int main()
{
int store[size];
srand((unsigned)time(0));
clock_t before, after;
for(int i=0;i<size;i++){
int x = ((int)rand()%100)+1;
store[i] = x;
}
before = clock();
quicksort(store,0,size-1);
after = clock();
cout<<"\n\n"<<"Sort success in : "<<((float)(after - before)/CLOCKS_PER_SEC)<<" secs\n\n";
for (int i = 0; i <size; i++)
cout<<store[i]<<",";
return 0;
}
when i'm using size = 8 ,it show answer but when i use size = 1024 so , answer not show.
help me to find the problem about this code. thank you
It's compile in visual studio 2010
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|