Shell sort won't work in this program (the algorithm itself works just fine) - Page 2
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 2 of 2 FirstFirst 12
Results 16 to 18 of 18

Thread: Shell sort won't work in this program (the algorithm itself works just fine)

  1. #16
    Join Date
    Apr 1999
    Posts
    27,431

    Re: Shell sort won't work in this program (the algorithm itself works just fine)

    Quote Originally Posted by devilsummer View Post
    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

  2. #17
    Join Date
    Apr 1999
    Posts
    27,431

    Re: Shell sort won't work in this program (the algorithm itself works just fine)

    Quote Originally Posted by devilsummer View Post
    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

  3. #18
    Join Date
    Feb 2013
    Posts
    11

    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

Page 2 of 2 FirstFirst 12

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center