Hi, I've just written a sort method for my top ten songs chart program, which just hold a list of the top ten songs.
Each records is made up off the following fields:
Chart Position :int
Song Title :string
Song Artist :string
Record Company :string
Price :double
The method sorts records by Chart Position fine, but when I try to sort by Song Artist and re compile it gives me a error like the following error:
"cannot apply > to string" or somthing.
How can I compaire the strings to see which is greater, I want to sort Song Artist alphabeticly.
Here is how I'm sorting by Chart Position (I'm using bubble sort as you cannot have more than 10 records).
To sort by Song ArtistCode:passes = 1; swap = true; while ( ( passes <= arrayToSort.length - 1 ) && ( swap = true ) ) { i = 0; swap = false; while ( i <= arrayToSort.length - 2 ) { if ( arrayToSort[i].chartPosistion > arrayToSort[i + 1].chartPosistion ) { tempRecord.chartPosistion = arrayToSort[i].chartPosistion; tempRecord.songTitle = arrayToSort[i].songTitle; tempRecord.songArtist = arrayToSort[i].songArtist; tempRecord.recordCompany = arrayToSort[i].recordCompany; tempRecord.price = arrayToSort[i].price; arrayToSort[i].chartPosistion = arrayToSort[i + 1].chartPosistion; arrayToSort[i].songTitle = arrayToSort[i + 1].songTitle; arrayToSort[i].songArtist = arrayToSort[i + 1].songArtist; arrayToSort[i].recordCompany = arrayToSort[i + 1].recordCompany; arrayToSort[i].price = arrayToSort[i + 1].price; arrayToSort[i + 1].chartPosistion = tempRecord.chartPosistion; arrayToSort[i + 1].songTitle = tempRecord.songTitle; arrayToSort[i + 1].songArtist = tempRecord.songArtist; arrayToSort[i + 1].recordCompany = tempRecord.recordCompany; arrayToSort[i + 1].price = tempRecord.price; swap = true; } i = i + 1; } passes = passes + 1; }
I did the same as above but changing the if from:
to:Code:if ( arrayToSort[i].chartPosistion > arrayToSort[i + 1].chartPosistion )
Code:if ( arrayToSort[i].songArtist > arrayToSort[i + 1].songArtist )


Reply With Quote
!!! THANKS GUYS !!! 