A* again!
hello,
Well I have my A* algorithm working well except one thing, the Qucksort I have written for my vector list is sorting them backwards for what I need. The largest costs are being pulled up, instead of being shoved down (which you have to do since you can't delete elements at the front of a vector, only back... correct??)
So how do you make a quicksort sort backwards??
I dont know how 2 posts got up.... so can a mod delete one so ppl don't get angry!
With most sorts, you will test if one item is smaller or larger than another item. When I learned quicksort, it was implemented using the partition algorithim to test if an item was less than or equal to a pre-chosen pivot value. Just swap your less than or equal to signs with greater than or equal to signs. [edit]I think that should work, why not?
Oh, and to delete a post, click on the "Edit" button on the right side of the post. Above the little Icons, there will be a checkbox that says "Delete?". Check it, and then click modify and it will be deleted.[/edit]
Oh, and to delete a post, click on the "Edit" button on the right side of the post. Above the little Icons, there will be a checkbox that says "Delete?". Check it, and then click modify and it will be deleted.[/edit]
i think this code should work... i haven't tried it...
Quicksort(A, p, r)
{
if (p > r)
{
q = Partition(A, p, r);
Quicksort(A, p, q);
Quicksort(A, q+1, r);
}
}
Partition(A, p, r)
{
x = A
Quicksort(A, p, r)
{
if (p > r)
{
q = Partition(A, p, r);
Quicksort(A, p, q);
Quicksort(A, q+1, r);
}
}
Partition(A, p, r)
{
x = A
;
i = p - 1;
j = r + 1;
while (TRUE)
{
repeat
do
{
j--;
}while (A[j]<x);
do
{
i++;
}while(A>x);
if (i > j)
Swap(A, i, j);
else
return j;
}
}
if you get some trouble and don't know what to do, let it be ascending sorted, then, swap it all.. ehheheeh.... not a good idea, but it seems quiet easy...??. ehehe...
This might seem silly, but why don't you get A* to read the list backwards?
Easy fix.
From,
Nice coder
Easy fix.
From,
Nice coder
Click here to patch the mozilla IDN exploit, or click Here then type in Network.enableidn and set its value to false. Restart the browser for the patches to work.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement