-
February 6th, 2013, 09:29 AM
#16
Re: Shell sort won't work in this program (the algorithm itself works just fine)
Originally Posted by devilsummer
That is why I posted this problem here, because I cant find a solution
Just in addition -- you wound up using char arrays to represent strings -- once you did that, then you need to know how to use char arrays, and obviously you didn't know how to do this.
You cannot compare char arrays (or any arrays) using the logical operators <, >, <=, >=, etc. You have to write a loop or call a function that loops over all the elements and determines which item is different in each array. In the case of char arrays, the function is strcmp.
If you had instead used a std::string, then all of that code you had would have worked, since <, >, <=, >=, etc. are all supported by std::string. The trick is that if you're writing this kind of code, use types that are supported by the operators used in such code.
Regards,
Paul McKenzie
-
February 6th, 2013, 09:31 AM
#17
Re: Shell sort won't work in this program (the algorithm itself works just fine)
Originally Posted by devilsummer
What you say is perfectly logical. I implemented the algorithm in a simple program and it works just fine. When I implement it in the code above with the same values as in the simple program it wont do anything (it doesn't sort the values)
I still don't think it works fine, since you're sorting garbage data if you have less than 100 items. You can't sort invalid, uninitialized data with good data.
That last parameter to ShellSort() must be the exact number of valid items in the array to sort, not 100.
Regards,
Paul McKenzie
-
February 6th, 2013, 09:51 AM
#18
Re: Shell sort won't work in this program (the algorithm itself works just fine)
Thank you Paul. I will switch to string and see what happens. I appreciate your help
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|