Why this dies
Author |
Message |
wtd
|
Posted: Thu Feb 02, 2006 10:48 pm Post subject: (No subject) |
|
|
Indeed.
|
|
|
|
|
 |
Sponsor Sponsor

|
|
 |
Tubs

|
Posted: Thu Feb 02, 2006 10:55 pm Post subject: (No subject) |
|
|
So no idea why its not declaring the end of the list properly?
|
|
|
|
|
 |
wtd
|
Posted: Thu Feb 02, 2006 11:00 pm Post subject: (No subject) |
|
|
I have no idea why anything in that library is written the way it is.
|
|
|
|
|
 |
Tubs

|
Posted: Thu Feb 02, 2006 11:01 pm Post subject: (No subject) |
|
|
Yeah. Fuck the library i'm making my own damn list. Excuse my french.
|
|
|
|
|
 |
Tubs

|
|
|
|
 |
Tubs

|
Posted: Sun Feb 12, 2006 10:26 pm Post subject: (No subject) |
|
|
Scratch that last post. Re-wrote program. Linked lists suck.
|
|
|
|
|
 |
Tubs

|
Posted: Thu Mar 30, 2006 9:55 pm Post subject: (No subject) |
|
|
code: |
void median_qsort( int a[], int p, int q, int piv ) /*to sort the subarray */
{ /* a[p:q] of array A into ascending order */
int i, j;
if( p < q )
{
/* Initially i and j point to the first and last items */
i = p;
j = q;
partition( a, &i, &j, piv ); /* partitions a[p:q] into a[p:j] and a[i:q] */
median_qsort( a, p, j, piv );
median_qsort( a, i, q, piv );
}
}
|
where piv is a value between 1 and 3 determining the location of the pivot (1 being the beginning, 2 being the middle and 3 being the end of the array)
code: |
void partition( int a[], int *i, int *j, int piv )
{
int pivot, temp;
pivot = median (a[*i], a[*j - 1], a[SIZE / 2]);
if ( piv == 1 )
{
if ( pivot == a[*j-1] )
{
temp = a[0];
a[0] = pivot;
a[*j-1] = temp;
}
else if ( pivot == a[SIZE/2] )
{
temp = a[0];
a[0] = pivot;
a[SIZE/2] = temp;
}
}
else if ( piv == 2 )
{
if ( pivot == a[*j-1] )
{
temp = a[SIZE/2];
a[SIZE/2] = pivot;
a[*j-1] = temp;
}
else if ( pivot == a[0] )
{
temp = a[SIZE/2];
a[SIZE/2] = pivot;
a[0] = temp;
}
}
else if ( piv == 3 )
{
if ( pivot == a[0] )
{
temp = a[*j-1];
a[*j-1] = pivot;
a[0] = temp;
}
else if ( pivot == a[SIZE/2] )
{
temp = a[*j-1];
a[*j-1] = pivot;
a[SIZE/2] = temp;
}
}
print_list ( a, SIZE );
do {
/* Find leftmost i such that a[i] >= Pivot.*/
while( &a[*i] <= &pivot )
{
(*i)++;
}
/* Find rightmost j such that a[j] <= Pivot.*/
while( &a[*j] >= &pivot )
{
(*j)--;
}
/* if i and j didn't cross over one another, swap */
if (*i <= *j)
{
temp = a[*i];
a[*i] = a[*j];
a[*j] = temp; /* a[i] and a[j] */
(*i)++; /* move i one space right */
(*j)--; /* move j one space left */
}
} while (*i >= *j); /* while the i and j pointers haven't crossed yet */
}
|
I was supplied the original code for quicksort and partition, and instructed to code the rest to make it median of three quicksort (main declares the piv variable). The median calculation works fine, as does the switching. The problem is that the program takes about 7 seconds between printing the list (print_list function) and it does not sort it at all. Any ideas where the error is? Any help is greatly appreciated!
|
|
|
|
|
 |
|
|