How to Sort an Array in C++? Sorting an array involves rearranging its elements in a specific order such as from smallest to largest element or from largest to smallest element, etc. In this article, we will learn how to sort an array in C++.Example:Input: arr ={5,4,1,2,3}Output: 1 2 3 4 5Explanation: arr is sorted in increasin
4 min read
C++ Program for Sorting all array elements except one Given an array, a positive integer, sort the array in ascending order such that the element at index K in the unsorted array stays unmoved and all other elements are sorted. Examples: Input : arr[] = {10, 4, 11, 7, 6, 20} k = 2; Output : arr[] = {4, 6, 11, 7, 10, 20} Input : arr[] = {30, 20, 10} k =
3 min read
C++ Program to Find the Second Largest Element in an Array In C++, an array is a data structure that is used to store multiple values of similar data types in a contiguous memory location. In this article, we will learn how to find the second largest element in an array in C++. Examples: Input: arr[] = {34, 5, 16, 14, 56, 7, 56} Output: 34 Explanation: The
3 min read
C++ Program for Sorting array except elements in a subarray Given an array A positive integers, sort the array in ascending order such that element in given subarray (start and end indexes are input) in unsorted array stay unmoved and all other elements are sorted.Examples : Input : arr[] = {10, 4, 11, 7, 6, 20} l = 1, u = 3 Output : arr[] = {6, 4, 11, 7, 10
2 min read
How to Sort a Vector in a Map in C++? In C++, we can create a map container where the values associated with keys is a vector. In this article, we will learn how to sort a vector within a map in C++. Example Input: myMap = { {3, {9, 7, 3}}, {5, {4, 2, 8, 1, 6}}, {8, {1, 2, 5, 8}} }; Output: Map: Key: 3, Sorted Vector: [3 7 9 ] Key: 5, S
2 min read
How to Sort a Deque in C++? In C++, the STL provides a container called a double-ended queue which is popularly known as deque. This container allows fast insertions and deletions at both ends of the container. In this article, we will learn how to sort a deque in C++. Example: Input: myDeque = {30, 10, 20,50,40} Output: 10 20
2 min read
Sort an array of string of dates in ascending order Given an array of strings dates[], the task is to sort these dates in ascending order. Note: Each date is of the form dd mmm yyyy where: Domain of dd is [0-31].Domain of mmm is [Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec].And, yyyy is a four digit integer. Examples: Input: dates[] =
7 min read
Sorting Vector of Arrays in C++ Given a vector of arrays, the task is to sort them. Examples: Input: [[1, 2, 3], [10, 20, 30], [30, 60, 90], [10, 20, 10]] Output: [[1, 2, 3], [10, 20, 10], [10, 20, 30], [30, 60, 90]] Input: [[7, 2, 9], [5, 20, 11], [6, 16, 19]] Output: [[5, 20, 11], [6, 16, 19], [7, 2, 9]] Approach: To sort the Ve
2 min read