Category Archives: C++ Programs

Sort an array of string of dates in ascending order

Given an array arr[] of N dates in the form of “dd-mm-yyyy”, the task is to sort these dates in ascending order. Examples: Input: arr[] = { “25-08-1996”, “03-08-1970”, “09-04-1994” } Output: 03-08-1970 09-04-1994 25-08-1996 Input: arr[] = { “14-02-1972”, “01-01-2001”} Output: 14-02-1972 01-01-2001 A simple solution that comes to our mind is to delete all ‘-‘ from… Read More »

Sort odd indices in ascending order and even indices in descending order of the string

Given a string S, the task is to sort odd indices in ascending order and even indices in descending order of the string. Examples: Input: S = “Cplusplus” Output: Cululspsp Explanation: Sort string S in ascending order: S = “Cululspsp” Replace odd indices in ascensing order and even indices in descending order. Input: S = “plusplus” Output: lulupsps… Read More »