Monday, July 27, 2009

C++, char string swap stuff. Mostly done?

The original question from the book is Modify the "selectionSort" function presented in this chapter so it searches an array of strings instead of an array of ints. Test the function with a driver program. Anyway, I have mostly completed the program. Could someone please tell me what is wrong with it and how to fix it please?

C++, char string swap stuff. Mostly done?
i'm really sorry to say that the lin you provided is not working..


.


.


.


but i can easily guess what is the problem..


in c++ you can compare basic/fundamental data types directly by using the comparison operators like %26gt; or %26lt;..


but for derived data types like strings(char arrays).. or any other class's object.. you cannot sirectly use the comparison operator ..


eg you cannot do the following..


if( str1 %26gt; atr2 ) do this;


..


.


.


.this is not possible../


to compare strings use the following..


if( strcmp( str1,str23) %26lt;0) {


str2 is greater..


}


else str1 is freater..


.


.


.


ir you are using the String class provided bu c++ STL.. then you can directly use the overloaded operators to compare the string objects..


.


.


.


eg.. you can do the fllowing...


String str1("abc");


String str2("abb");.


.


now str1 %26lt; str2 will return true..





/


/


refrer to your compler manual for further details..


or else try searching string comparision on net..
Reply:Hm... "driver program" to implement sorting algorithm?! What does it mean?
Reply:Your passing an entire array that is multi-dimensional.





You should print the values for





array[index], minValue





and see what they are.
Reply:Please Copy and paste i do not do downloads thanks


when you search an array first make sure everything is in bounds


No comments:

Post a Comment