general shell sort
Displaying 1-8 of 8 total.
1
Please enter a numerical value for the importance of this sticky.
Enter 0 to unsticky.
gannon

here is a general shell sort(I like more generalized functions)

void shellSort(string intname, int array_size)
{
int i, j, increment, temp;
int boolA,boolB;


increment = 3;
while (increment > 0)
{
for (i=0; i < array_size; i++)
{
j = i;
temp = GetIntArray(intname, i);

if(j >= increment)
boolA = 1;
else
boolA = 0;
if(GetIntArray(intname, j-increment) > temp)
boolB = 1;
else
boolB = 0;
while (boolA && boolB){

SetIntArray(intname, j,GetIntArray(intname, j-increment));
j = j - increment;

if(j >= increment)
boolA = 1;
else
boolA = 0;
if(GetIntArray(intname, j-increment) > temp)
boolB = 1;
else
boolB = 0;
}
SetIntArray(intname, j,temp);
}
if (increment/2 != 0)
increment = increment/2;
else if (increment == 1)
increment = 0;
else
increment = 1;
}
}

my only consern is I can't seem to get complex conditionals to work (does anyone know the trick in verge)

Posted on 2004-08-03 05:02:53

Gayo

The trick is to not do it, because they don't work. vecna plans to add support for them someday, but for now you have to do unpleasant workarounds like this.

Posted on 2004-08-03 05:13:48

mcgrue

I basically just use excessive functional decomposition in lieu of very long conditionals.

Posted on 2004-08-03 06:18:22

gannon

I found a nice quick sort that doesn't need it
here it is (could you change the title to say general shell and quick sorts)

//general quicksort just pass the name of the array and the array size
//this is modified from http://www.csse.monash.edu.au/~lloyd/tildeAlgDS/Sort/Quick/ to work with verge
void quicksort(string array_name, int array_size)
{
quick(array_name, 0, array_size);
}
void quick(string array_name, int lo, int hi)
{
int leftp, rightp, median, temp;

if( hi > lo ) /* i.e. at least 2 elements, then */
{
leftp=lo;
rightp=hi;
median=GetIntArray(array_name, lo); /* NB. just an estimate! */

while(rightp >= leftp)
{
while(GetIntArray(array_name, leftp) < median)
leftp++;


while(GetIntArray(array_name, rightp) > median)
rightp--;


if(leftp <= rightp){

//swap:
temp=GetIntArray(array_name, leftp);
SetIntArray(array_name, leftp ,GetIntArray(array_name, rightp));
SetIntArray(array_name, rightp, temp);
leftp++;
rightp--;
}
}


quick(array_name, lo, rightp);// divide and conquer
quick(array_name, leftp, hi);
}
}

Posted on 2004-08-03 06:47:44 (last edited on 2004-08-03 06:49:53)

mcgrue

This is very useful. I didn't even think to use the new accessor functions in this manner, and I was the one who asked for them ;)

I shall be using this in Sully immediately. This is so very useful, that I shall award you with an avatar... if you'd please email me one ;)

Posted on 2004-08-03 09:35:41

gannon

thanks I will look for one and send it too you.
for now the shell sort will be better to use (the get and set need to be faster to allow the array to be bigger to use the quicksort effectively)(I think they will be faster when the trees get done)

Posted on 2004-08-03 16:55:36

vecna

... That is way cool. I didn't think of that use of the set/get functions either.

Posted on 2004-08-03 17:14:40

gannon

you can even modify it to pass in a string so it will support parallel arrays (keeping them both synchronized)

Posted on 2004-08-03 17:54:38


Displaying 1-8 of 8 total.
1
 
Newest messages

Ben McGraw's lovingly crafted this website from scratch for years.
It's a lot prettier this go around because of Jon Wofford.
Verge-rpg.com is a member of the lunarnet irc network, and would like to take this opportunity to remind you that regardless how babies taste, it is wrong to eat them.