Cant figure out error on bubble sort.

Ask for help with your homework/assignments in this forum!

Moderators: Darobat, RecursiveS, Dante Shamest, Bugdude, Wizard

Cant figure out error on bubble sort.

Postby Namen » Wed Dec 03, 2003 10:39 pm

The problem now is that the array needs to be sorted by last name. This is where im having problems. Not going to post all of code.

Class Declaration

Code: Select all
class voter
{

friend void sortid(voter v1[], int size); <--- this is for sortby id number
friend void sortlastname(voter v1[], int size); <----sort by lastname


private:     
     int  idnumber;
     char lastname [25];
     char firstname[25];
     char party        [2];
     int  birthyear;
     int  currentage;

public:
     voter();
     voter(int,char[], char[], char[], int, int);
     voter(const voter&);
     void Add();
     void Edit();
     void operator = (const voter&);
     void print(int);
     void disksave(ofstream& outfile);
     ~voter();

};

and now here is the code i attempt to use for sorting by lastname. here are errors im getting.

:\Documents and Settings\Admin\Desktop\Project 4\Project4.cpp(322) : error C2664: 'strcmp' : cannot convert parameter 2 from 'bool' to 'const char *'
Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
C:\Documents and Settings\Admin\Desktop\Project 4\Project4.cpp(323) : error C2146: syntax error : missing ')' before identifier 'min'
C:\Documents and Settings\Admin\Desktop\Project 4\Project4.cpp(325) : error C2228: left of '.swap' must have class/struct/union type
Error executing cl.exe.

Code: Select all
void sortArray (voter n[], int size) {
  int i, j;
  int min; 
  for ( i=0; i < size -1; i++ ) { //size- 1 because the last  element is automaticly in order
    min = i; // min is the index of smallest element that compare to the rest.
    /*this loop find the smallest element and */
    for (j = i+1; j < size; j++)
       if ( strcmp(n[j].lastname, n[min].lastname < 0 )
           min = j;
   /*after this for loop min should be the index  of smallest element
    n[i].lastname.swap(n[min].lastname);
  }
}
Namen
 

Postby devil_slayer » Thu Dec 04, 2003 8:40 am

Use code tags!

You might have figured already that this:

Code: Select all
if ( strcmp(n[j].lastname, n[min].lastname < 0 )


is suppoused to be like this:

Code: Select all
if ( strcmp(n[j].lastname, n[min].lastname) < 0 )
User avatar
devil_slayer
 
Posts: 489
Joined: Wed Oct 01, 2003 3:44 am
Location: Warsaw, POLAND

Postby Namen » Thu Dec 04, 2003 8:45 am

ya i got it owrking thanks...
Namen
 


Return to Homeworks

Who is online

Users browsing this forum: No registered users and 1 guest