| Z feng (57) | |||
|
I know there are couple example on the other post. But i haven't studied the most of those kind code. i only studied #include<cstring> .There is my idea, I know it's wrong. I don't know how the strcmp defined the letters' value.
How to improve it to make it work correctly? or any other method to do that? | |||
|
Last edited on
|
|||
| blueberry (110) | |
|
Can you explain what its supposed to do and how its failing to do that? All I can tell is you have some kind of linked list. A word of note: strcmp(&p->Cname[1],&c->Cname[1])I haven't got the slightest clue what your trying to do here. Currently it compares the first string to the second string, discounting the first letter. Very odd. NVM: just read your title. Your trying to sort a linked list. First of all, you need a sorting algorithm. Read this: http://en.wikipedia.org/wiki/Bubble_sort. Second of all, I highly suggest you do not use a linked list to do this. Most easy to read material is written for normal arrays and singly linked lists are hard to use. | |
|
Last edited on
|
|
| Z feng (57) | |
|
name is an array, so what I think is i could only compare the first char of the name. It might be wrong, it's just what I thought. When I input name, it suppose to insert the name at the right position depending on the alphabetical order. I said it fails is because according what I put, the order is not right . Such as: Amy, Bob, Cindy, Dan... | |
|
|
|
| fun2code (1063) | |
|
strcmp() function usage: Arguments are entire strings. Call like so strcmp( p->Cname, c->Cname );strcmp compares the entire strings lexicographically (as in dictionary). strcmp( strA, strB ) returns: -1 if strA < strB +1 if strA > strB 0 if strA == strB @blueberry: He is inserting the elements in order as they are added. No sorting needed! | |
|
|
|
| Z feng (57) | |
| thanx! I fixed it! | |
|
|
|