Implement quick sort algorithm with faulty results. Details of what I want to do can be found at the video: https://courses.edx.org/courses/course-v1:HarvardX+CS50+X/courseware/cdf0594e6a80402bbe902bb107fd2976/22251a2b00ac42788c70ca6f6ccbe7fd/ Does break command take me out of inner loop or both loops? Below you'll find the code, any help will be welcome.
int main (void)
{
// Array of integers to be sorted
int list[] = { 3, 9, 8, 5, 7, 6, 4, 2, 1};
int arrayIndexLimit = (sizeof (list) / sizeof (int)) - 1;
int temp = 0;
// "J" separates sorted part of array from unsorted one
for (int j = 0; j < arrayIndexLimit; j++)
{
// Find smallest value in unsorted part of array
for (int i = j; i <= arrayIndexLimit; i++)
{
// Put smallest value in jth position
if (list[i] < list[arrayIndexLimit])
{
temp = list[j];
list[j] = list[i];
list[i] = temp;
break;
}
// Pivot (last item of array) is the smallest
if (i == arrayIndexLimit)
{
temp = list[i];
list[i] = list[j];
list[j] = temp;
break;
}
}
// Print sorted list
}