lundi 27 avril 2020

Sorting vector(BubbleSort)

I have class Date, functions bubbleSort and printVector. So my task is: Use the function bubbleSort to sort vector type objects Date. I've done something but it doesn't works, so can anyone help me with this? Function bubble sort(doesn't works with "Date", works fine with integers ,strings...):

template<typename T>
void bubbleSort(vector<T> &vec) {
    bool swapp = true;
    while (swapp) {
        swapp = false;
        for (unsigned int i = 0; i < vec.size() - 1; i++) {
            if (vec[i] > vec[i + 1]) {
                swap(vec[i], vec[i + 1]);
                swapp= true;

In main program i tried to do this:

 Date date(15,3,1980);
     Date date1(13,6,2010);
     vector <Date> dates;
     dates.push_back(date);
     dates.push_back(date1);
    bubbleSort(dates);
    printVector(dates);

Aucun commentaire:

Enregistrer un commentaire