CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Dec 2010
    Posts
    4

    please check my problem

    this is parallel quicksort algorithm using .net concurrency



    #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

  2. #2
    Join Date
    Dec 2010
    Posts
    4

    Re: please check my problem

    this code compile and run in microsoft visual studio 2010

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured