What will be the output of the given C++ code?
#include <bits/stdc++.h>
using namespace std;
int main()
{
int arr[] = {1, 3,4,2,5};
int n = sizeof(arr)/sizeof(arr[0]);
sort(arr+2, arr+n, greater<int>());
int a;
for (int a = 0; a < n; a++)
cout << arr[a] << " ";
return 0;
}
#include <bits/stdc++.h>
using namespace std;
int main()
{
int arr[] = {1, 3,4,2,5};
int n = sizeof(arr)/sizeof(arr[0]);
sort(arr+2, arr+n, greater<int>());
int a;
for (int a = 0; a < n; a++)
cout << arr[a] << " ";
return 0;
}
A. 1 2 3 4 5
B. 1 5 4 3 2
C. 5 4 3 2 1
D. 1 3 5 4 2
Answer: Option D
Related Questions on Sorting Algorithms
What is the time complexity of Bubble Sort in the average case?
A. O(n log n)
B. O(n)
C. O(n2)
D. O(n3)
Which sorting algorithm is based on the divide-and-conquer strategy?
A. Insertion Sort
B. Quick Sort
C. Selection Sort
D. Insertion Sort
Which sorting algorithm uses a "pivot" element to partition the array into sub-arrays?
A. Merge Sort
B. Heap Sort
C. Counting Sort
D. Quick Sort
Join The Discussion