Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Why this dies
Index -> Programming, C++ -> C++ Help
Goto page Previous  1, 2, 3, 4
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
wtd




PostPosted: Thu Feb 02, 2006 10:48 pm   Post subject: (No subject)

Indeed.
Sponsor
Sponsor
Sponsor
sponsor
Tubs




PostPosted: 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




PostPosted: 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




PostPosted: 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




PostPosted: Sun Feb 12, 2006 8:48 pm   Post subject: (No subject)

I cannot figure out why this program dies (no error messages on my IDE either Sad) Any help is greatly appreciated as always Smile

The program is supposed to take an integer, use the division by 2 method to determine the binary equivalent using stacks.



binary.zip
 Description:

Download
 Filename:  binary.zip
 Filesize:  2.58 KB
 Downloaded:  122 Time(s)

Tubs




PostPosted: Sun Feb 12, 2006 10:26 pm   Post subject: (No subject)

Scratch that last post. Re-wrote program. Linked lists suck.
Tubs




PostPosted: 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!
Display posts from previous:   
   Index -> Programming, C++ -> C++ Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 4 of 4  [ 52 Posts ]
Goto page Previous  1, 2, 3, 4
Jump to:   


Style:  
Search: