PLEASE HELP [C++] alphabetical sort ?!?!? http://www.daniweb.com/software-development/cpp/threads/421354/alphabetical-sort-class-object-vector-array- details in there
Stacey Warren - Expert brainly.com
Hey! We 've verified this expert answer for you, click below to unlock the details :)
At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga.
Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus.
Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.
I got my questions answered at brainly.com in under 10 minutes. Go to brainly.com now for free help!
In both your friends instructions and the advice given in the forum you have the answer you need. The user on the forum even wrote the function for you, leaving you to fill in the condition.
You simply need to decide how you will evaluate one object over another and place that as the conditional in the if statement.
Perhaps this will clear it up a little more for you: http://www.cplusplus.com/reference/algorithm/sort/
Y not just use the ASCII values?
espex - i still don't ge tit, and i did check that page already.
Not the answer you are looking for? Search for more explanations.
There are many different sorting algorithms. Which one to use depends on how many items need sorting and how random their order is before sorting. Choosing which algorithm is up to you.
All sort algorithms require two helper functions. One to compare the two items in question, and another to swap them if needed. Swapping is simple enough. Comparison functions are needed for different data types. Usually, they return an int. Usually they return -1 for ab. The calling code handles what to do depending on the int returned.
string has a comparison member function that follows the norm, and it's not too bad to learn. Write a separate test program to get used to it. Mine was 10 lines of code.
The sort() function takes three arguments, a starting point, an ending point, and a means to compare the two. Your friend gave you these instructions:
"Just create a new function that takes two employee objects by reference and returns a Bool. The whole function is one if else statement where you check whether the first parameter name is less than the second parameter name and return true or false accordingly. Then simply pass the name of the function to the sort function as if it was a variable"
So if the method you create is called mySort(), you would call sort(start, end, mySort), your task is to create that comparison method. One such way to compare would be to take in a record, pull the last name and compare the first letters. If you had Smith and Jones and compared S to J, then J has a value less than that of S so you decide how to handle that, ascending or descending sort.
that's roughly what i've been working with, except i can't get it working, so i don't need "roughly", i need like exactly, in context, because i don't know this t all and i'm not figuring it out
As I did not see anywhere that you could not use string compare then you could easily adapt the example given here: http://www.cplusplus.com/reference/string/string/compare/ to return which string is greater.
Likewise you could compare the first character of each string and let that be your test for equality as is done in this example: http://www.cplusplus.com/reference/clibrary/cstring/strncmp/
OR you could even say if(record::name1 > record::name2) return record::name1;
Hope that helps.
how do i go through and sort all of them that way... i'm sorry hah what can i say i don't GET IT but ok i'll work with it just answer me that and let's see
Ultimately, strings are arrays of characters. You can iterate through them one character at a time.