How to sort an array of dates in C/C++? Given an array of dates, how to sort them. Example: Input: Date arr[] = {{20, 1, 2014}, {25, 3, 2010}, { 3, 12, 1676}, {18, 11, 1982}, {19, 4, 2015}, { 9, 7, 2015}} Output: Date arr[] = {{ 3, 12, 1676}, {18, 11, 1982}, {25, 3, 2010}, {20, 1, 2014}, {19, 4, 2015}, { 9, 7, 2015}} We strongly recommend
3 min read
Create a Sorted Array Using Binary Search Given an array, the task is to create a new sorted array in ascending order from the elements of the given array.Examples: Input : arr[] = {2, 5, 4, 9, 8} Output : 2 4 5 8 9 Input : arr[] = {10, 45, 98, 35, 45} Output : 10 35 45 45 98 The above problem can be solved efficiently using Binary Search.
9 min read
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 =
6 min read
Sort an array of strings according to string lengths We are given an array of strings, we need to sort the array in increasing order of string lengths.Examples: Input : {"GeeksforGeeeks", "I", "from", "am"}Output : I am from GeeksforGeeks Input : {"You", "are", "beautiful", "looking"}Output : You are looking beautiful A simple solution is to write our
10 min read
Sort elements by frequency using STL Given an array of integers, sort the array according to frequency of elements. If frequencies of two elements are same, print them in increasing order. Examples: Input : arr[] = {2, 3, 2, 4, 5, 12, 2, 3, 3, 3, 12} Output : 3 3 3 3 2 2 2 12 12 4 5 Explanation : No. Freq 2 : 3 3 : 4 4 : 1 5 : 1 12 : 2
7 min read