Tuesday, November 26, 2024
Google search engine
HomeData Modelling & AIC++ program for Sorting Dates using Selection Sort

C++ program for Sorting Dates using Selection Sort

C




// C++ program for sorting dates using selection sort
#include<bits/stdc++.h>
using namespace std;
struct date
{
    int day;
    int month;
    int year;
};
 
int main()
{
    struct date input[5];
    for(int i=0; i<5; i++)
    {
        cin>>input[i].day;
        cin>>input[i].month;
        cin>>input[i].year;
 
    }
    for (int i=0; i<4; i++)
    {
        for (int j=i+1; j<5; j++)
        {
            if (input[i].year > input[j].year)
            {
                struct date temp = input[i];
                input[i] = input[j];
                input[j] = temp;
            }
            else if (input[i].year == input[j].year && input[i].month > input[j].month)
            {
                struct date temp = input[i];
                input[i] = input[j];
                input[j] = temp;
            }
            else if (input[i].year == input[j].year && input[i].month == input[j].month && input[i].day > input[j].day)
            {
                struct date temp = input[i];
                input[i] = input[j];
                input[j] = temp;
            }
 
        }
    }
 
 
    for(int i=0; i<5; i++)
    {
        cout<<input[i].day<<" "<<input[i].month<<" "<<input[i].year;
        cout<<endl;
    }
}


This program is contributed by Dinesh T.P.D. Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above

Feeling lost in the world of random DSA topics, wasting time without progress? It’s time for a change! Join our DSA course, where we’ll guide you on an exciting journey to master DSA efficiently and on schedule.
Ready to dive in? Explore our Free Demo Content and join our DSA course, trusted by over 100,000 neveropen!

RELATED ARTICLES

Most Popular

Recent Comments