![]() |
In C++, vectors are dynamic arrays and the median is a middle value when data is sorted in ascending order. In this article, we will learn how to find the median of all elements in a sorted vector in C++. Example Input: myVector = {10, 20, 30, 40, 50}; Output: Median is 30 Finding Median of Sorted Vector in C++To find the median of a sorted vector in C++, first check if the size of the vector is even or odd.
C++ Program to Find the Median of Sorted VectorThe below example demonstrates how we can find the median of elements stored in a sorted vector in C++. C++
Output Median of oddVec: 30 Median of evenVec: 35 Time Complexity: O(1), as the vector is already sorted |
Reffered: https://www.geeksforgeeks.org
C++ |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 14 |