+ Reply to Thread
Results 1 to 5 of 5

Thread: C++

  1. #1
    daman371 is offline x10 Sophmore daman371 is an unknown quantity at this point
    Join Date
    Nov 2006
    Location
    Louisiana
    Posts
    130

    C++

    Can anyone convert this quicksort to use a linked list?


    Code:
    void Quicksort(int set[], int start, int end) 
    { 
       int pivotpoint; 
     
       if (start < end) 
       { 
          pivotpoint = Partition(int set[], start, end); 
          QuickSort(set, start, pivotpoint-1); 
          QuickSort(set, pivotpoint+1, end); 
       } 
    } 
     
    int Partition(int set[], int start, int end) 
    { 
       int pivotvalue, 
           pivotindex, 
           mid; 
     
       mid = (start + end) /2; 
       swap(set[start], set[mid]); 
       pivotindex = start; 
       pivotvalue = set[start]; 
       for (int scan = start + 1; scan <= end; scan++) 
       { 
          if (set[scan] < pivotvalue) 
          { 
             pivotindex++; 
             swap(set[pivotindex], set[scan]); 
          } 
       } 
       swap(set[start], set[pivotindex]); 
       return pivotindex; 
    }
    Last edited by daman371; 03-03-2009 at 01:57 PM.

  2. #2
    ConEd is offline x10Hosting Member ConEd is an unknown quantity at this point
    Join Date
    Feb 2009
    Posts
    3

    Re: C++

    Checkout the STL code or C code for Qsort and you should find a linkedlist implementation.

  3. #3
    daman371 is offline x10 Sophmore daman371 is an unknown quantity at this point
    Join Date
    Nov 2006
    Location
    Louisiana
    Posts
    130

    Re: C++

    Do you have a link? I haven't been able to find one that works.

  4. #4
    daman371 is offline x10 Sophmore daman371 is an unknown quantity at this point
    Join Date
    Nov 2006
    Location
    Louisiana
    Posts
    130

    Re: C++

    *bump*

  5. #5
    nahsorhseda's Avatar
    nahsorhseda is offline x10 Sophmore nahsorhseda is an unknown quantity at this point
    Join Date
    Oct 2007
    Location
    mumbai
    Posts
    116

    Re: C++

    simply point one object to another!
    or
    use arrays instead ,since linked lists are slow when accessing/searching large amounts of data in a linked list
    glad to resolve problems in c++ n php

+ Reply to 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
x10hosting free hosting for the masses
dedicated servers