c++ bubble sort help!

Im trying to figure out how to do a bubble sort with the program i have created. My program needs to get the dates from the text file and if it finds two of the same date, it needs deletes one and keeps the other. I need to do a bubble sort so i can do something like if ( arr[i] == arr[i+1]) delete it and so forth.

What i dont know is how to set up the bubble sort as in what goes in the ( ) with the info that i have in my program

Any help would be appreciated.


here is my code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107

#include <iostream>
#include <fstream>

using namespace std;
class DateType
{
public:   
          
  void readDate(ifstream &dates);
  void compareDate();           
  void printDate();
  bool  operator == ( DateType b);
   bool operator > ( DateType a);
   bool operator <( DateType c);

  
  
private:
        
    int month;
    int day;
    int year;
    
} ;

  void DateType :: readDate(ifstream &dates) // reads in the info from the text file and puts it into the array
  {
    
    
    
       
      dates >> month;
      dates >> day;
      dates >> year;
    
  }
  void DateType::compareDate( )
  { 
      
      
   }
   
  
  void DateType:: printDate(  )   // gets the info from readDate and prints out the dates in format
  {
  
      cout << month << "/" << day << "/" << year << endl;
    
  }
  
  
  
  
  
  
     bool DateType :: operator == ( DateType b)
  {
       printDate();
    if( year == b.year && month == b.month && day == b.day)
    return true;
    else
    return false;   
}   
   bool DateType :: operator >( DateType a)
  {
       printDate();
    if( year > a.year && month > a.month && day > a.day)
    return true;
    else
    return false;   
}   


bool DateType :: operator <( DateType c)
  {
       printDate();
    if( year < c.year && month < c.month && day < c.day)
    return true;
    else
    return false;   
}   
 



int main()
{   
    ifstream dates("dates.txt");
    
    
  DateType arr[20]; 
  DateType myDate;
 
 while (!dates.eof())
  {
  myDate.readDate(dates);
   myDate.printDate();
}
  
                         
  
     

  system("pause");
  return 0;
}


the compareDates is where i was planning on putting the bubblesort
Last edited on
Topic archived. No new replies allowed.