Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Selected Reading
K’th Smallest/Largest Element using STL in C++
In this tutorial, we are going to write a program that finds the k-th smallest number in the unsorted array.
Let's see the steps to solve the problem.
- Initialise the array and k.
- Initialise a empty ordered set.
- Iterate over the array and insert each element to the array.
- Iterate over the set from 0 to k - 1.
- Return the value.
Example
Let's see the code.
#includeusing namespace std; int findKthSmallestNumber(int arr[], int n, int k) { set set; for (int i = 0; i Output
If you run the above code, then you will get the following result.
23Conclusion
If you have any queries in the tutorial, mention them in the comment section.
Advertisements
