C++

daman371

New Member
Messages
130
Reaction score
0
Points
0
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:

ConEd

New Member
Messages
3
Reaction score
0
Points
0
Checkout the STL code or C code for Qsort and you should find a linkedlist implementation.
 

nahsorhseda

Member
Messages
116
Reaction score
0
Points
16
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
 
Top