bubble sort vector

This is a discussion on bubble sort vector within the C++ Programming forums, part of the General Programming Boards category; I can't seem to figure out to sort this problem. I've load up a bunch of actors and presidents into ...

  1. #1
    Registered User
    Join Date
    Oct 2010
    Posts
    4

    bubble sort vector

    I can't seem to figure out to sort this problem.
    I've load up a bunch of actors and presidents into a vector call people.

    1732 2 22 1789 4 30 George Washington
    Actor John Cusack 1966 6 28 2012

    Now what I'm trying to do is sort the vector by the date of birth. On the president's data there are 2 dates. One of them is the date of birth and the other is their term start. Both class are a subclass of person. I store the date as a date object to the vector.

    So, how do I compare the birthday from the vector?
    PHP Code:
        for(int i 0people.size();i++)
            for(
    int j i+1people.size(); j++)
            {
                    if(
    people[i] > people[j])
                        
    std::swap(people[i],people[j]);

            }



  2. #2
    Programming Wraith GReaper's Avatar
    Join Date
    Apr 2009
    Location
    Greece
    Posts
    1,602
    Quote Originally Posted by yes2 View Post
    So, how do I compare the birthday from the vector?
    Code:
    if(people[i].date > people[j].date)
    Or something like that. Have you overloaded '>' operator for the date object?
    Devoted my life to programming...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Can't see the bubbling in the bubble sort.
    By Krash005 in forum C Programming
    Replies: 8
    Last Post: 09-10-2009, 09:41 PM
  2. Vector Addition Using OOP?
    By everydaybh in forum C++ Programming
    Replies: 3
    Last Post: 04-09-2009, 05:09 AM
  3. How can i made vectors measuring program in DevC++
    By flame82 in forum C Programming
    Replies: 1
    Last Post: 05-07-2008, 02:05 PM
  4. Bubble Sort, Qucik Sort
    By insomniak in forum C Programming
    Replies: 2
    Last Post: 03-15-2003, 03:54 PM
  5. Operators for 3D Vector Mathematics
    By Anarchist in forum C++ Programming
    Replies: 10
    Last Post: 01-31-2003, 06:33 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21