Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

QuickSort Problems

Status
Not open for further replies.

KT927

Programmer
Joined
Oct 1, 2000
Messages
5
Location
US
Here is the updated and neatly typed code. I'm not sure what is missing or what is correct.

KT927




void Swap (float&x, float&y)
{
float temp;
temp = x;
x = y;
y = temp;
}

int Partition(float kArray[], int first, int last)
{
float Pivot = kArray[first];

int left = first;
int right = last;

while(left<right)
{
while (kArray
>Pivot)
{
right = right -1;

while((kArray
<=Pivot) && (left<right))
{
left=left+1;

Swap(kArray
, kArray
);
}
Swap(kArray[Pivot], kArray
);
}
return right;
}

}

void Quicksort(float kArray[], int first, int last)
{
int PivotIndex;
if (first < last)
{
PivotIndex = Partition(kArray, first, last);
Quicksort(kArray, first, PivotIndex-1);
Quicksort(kArray, PivotIndex+1, last);
}

}

[sig][/sig]​
 
I hate that this keeps happening. Let's try this again. KT927


void Swap (float&x, float&y)
{
float temp;
temp = x;
x = y;
y = temp;
}

int Partition(float kArray[], int first, int last)
{
float Pivot = kArray[first];
int left = first;
int right = last;

while(left<right)
{
while (kArray
>Pivot)
{
right = right -1;
while((kArray
<=Pivot) && (left<right))
{
left=left+1;
Swap(kArray
, kArray
);
}
Swap(kArray[Pivot], kArray
);
}
return right;
}
}
void Quicksort(float kArray[], int first, int last)
{
int PivotIndex;
if (first < last)
{
PivotIndex = Partition(kArray, first, last);
Quicksort(kArray, first, PivotIndex-1);
Quicksort(kArray, PivotIndex+1, last);
}

} [sig][/sig]​
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top