Ad
  • Custom User Avatar

    No prob! Glad to help!

  • Custom User Avatar

    You are getting an index out of bounds error because you are comparing an index to an array length. The index of the last number will be 1 less than the array length. So in this array: {3,2,1} the array length is 3, but the index of the last number is 2. So when you check middle_idx < array.Length, it makes it so that it tries to run one more time. On this last run, it tries to grab a number from array[3] which doesnt exist (this throws the error). To fix it, simply change array.Length to array.Length - 1

  • Custom User Avatar

    Ah, you are using Max() and Min() on the raw string. Was wondering.

    Max() when used on a string will sort all chars and return the last char. '9' is the highest ASCII char in the string, ' ' (space) is the lowest.

    As I said, you need to convert it into a list of numbers.

  • Custom User Avatar

    When you sort a list of strings, you may not get the result you think.
    You'll have to convert the list of strings to a list of numbers.

    You can get more help by reading other comments, since this is a very common mistake.

  • Custom User Avatar

    What type was the list?

  • Custom User Avatar

    C#?
    use string.Join at the last step ;-)

  • Custom User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Custom User Avatar

    Hi Coerdringer,

    SIGSEGV is raised when you try to manipulate with some memory segment you have not access to.

    Your problem in the modified version is at the line numbers.erase(numbers.end());
    end() returns a reference to a theoretical item, that would follow the last element in the vector. So, it's not a reference to the last item in your vector. Your should do in this case numbers.end() - 1.

    In your not modified version from Codelite you do numbers.erase(numbers.begin());. In comparison to end(), begin() returns a reference to the first item in an array. Therefore you didn't have problem.