Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
No prob! Glad to help!
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 checkmiddle_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 fromarray[3]
which doesnt exist (this throws the error). To fix it, simply changearray.Length
toarray.Length - 1
Ah, you are using
Max()
andMin()
on the raw string. Was wondering.Max()
when used on a string will sort allchar
s and return the lastchar
.'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.
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.
What type was the list?
C#?
use
string.Join
at the last step ;-)This comment is hidden because it contains spoiler information about the solution
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 casenumbers.end() - 1
.In your not modified version from Codelite you do
numbers.erase(numbers.begin());
. In comparison toend()
,begin()
returns a reference to the first item in an array. Therefore you didn't have problem.