C++: I am trying to sort the given array in the main method but I am getting the following error:
error: no match for ‘operator<’ (operand="" types="" are="" ‘std::basic_ostream’="" and="" ‘void’)="" cout="">’>< "\nsorted="" array:="" "="">< sortarray(arr,="">
Code:
void sortArray(int arr[], int length) { for (int i = 0; i < length;="" i++)=""> for (int j = i + 1; j < length;="" j++)=""> if (arr[j] < arr[i])=""> // Swaps values int temp = arr[i]; arr[i] = arr[j]; arr[j] = temp; } } } cout <> for (int i = 0; i < length;="" i++)=""> cout <> if (i < length="" -=""> cout < ",=""> } cout <>} // Sort Array
int main() {
int arr[] = {3, 4, 1, 2};int length = sizeof(arr) / sizeof(arr[0]);
cout < "\nsorted="" array:="" "="">< sortarray(arr,="">
}
Already registered? Login
Not Account? Sign up
Enter your email address to reset your password
Back to Login? Click here