I am currently trying to use a quicksort on an array already created in a file. I'm having some difficulty. I'm not sure how I output the QuickSort. I know I need the Function header in my main and in the header file. I know the function needs a cout statement, but I'm not sure how. The code below is what I have so far.
void Swap (float&x, float&y)
{
float temp;
temp = x;
x = y;
y = temp;
}
void Partition(float kArray[], int first, int last, int& PivotIndex)
{
float Pivot = kArray[first];
int left = first;
int right = last;
while(left<right)
{
while (kArray
void Swap (float&x, float&y)
{
float temp;
temp = x;
x = y;
y = temp;
}
void Partition(float kArray[], int first, int last, int& PivotIndex)
{
float Pivot = kArray[first];
int left = first;
int right = last;
while(left<right)
{
while (kArray
>Pivot)
{
right = right -1;
while((kArray
{
right = right -1;
while((kArray
<=Pivot) && (left<right))
{
left=left+1;
Swap(kArray
{
left=left+1;
Swap(kArray
, kArray
);
}
int PivotIndex = left;
}
}
}
void Quicksort(float kArray[], int first, int last)
{
int PivotIndex;
if (first < last)
{
Partition(kArray, first, last, PivotIndex);
Quicksort(kArray, first, PivotIndex-1);
Quicksort(kArray, PivotIndex+1, last);
}
int i;
for (i = 0; i<PivotIndex; i++)
cout<<kArray<<"\n";
} [sig][/sig]
}
int PivotIndex = left;
}
}
}
void Quicksort(float kArray[], int first, int last)
{
int PivotIndex;
if (first < last)
{
Partition(kArray, first, last, PivotIndex);
Quicksort(kArray, first, PivotIndex-1);
Quicksort(kArray, PivotIndex+1, last);
}
int i;
for (i = 0; i<PivotIndex; i++)
cout<<kArray<<"\n";
} [sig][/sig]