Issue with bubble sorting vectors
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: Issue with bubble sorting vectors

  1. #1
    Join Date
    Feb 2013
    Posts
    2

    Issue with bubble sorting vectors

    Hello,
    I'm doing a project where I have to store information gathered (temperature and the time it was taken in seconds) in two seperate vectors. After an unknown amount of data has been enterd, and the end-of-file has been reached, I have to display the highest temperature and the time(s) it occured (bear in mind that the highest temperature may be recorded more than once). The output of that part should be as follows:

    Highest temperature: 51
    Recorded at time(s):
    22:45
    2:27


    Something like that. The time should also be converted to hours and minutes. To the point: I've done some research on bubble sorting, but they only use it for arrays. I'd like to know if anyone can help me gain some insight on using bubble sort in this scenario. I've been struggling with this for quite some time now.

    Thanks

  2. #2
    Join Date
    Apr 1999
    Posts
    27,422

    Re: Issue with bubble sorting vectors

    Quote Originally Posted by Grape Wizard View Post
    Hello,
    I'm doing a project where I have to store information gathered (temperature and the time it was taken in seconds) in two seperate vectors.
    Why two separate vectors? What if you had 10 other pieces of data concerning the weather? Create 12 vectors?
    Code:
    struct WeatherData
    {
        double temperature;
        long  timeRecorded;
        // any other information concerning the weather for that particular 
    };
    Then you create an array or vector of the struct. The struct contains all the information needed for one weather item. Then you sort on the temperature field -- all other fields will follow along for the ride when/if you swap items in the sort.
    To the point: I've done some research on bubble sorting, but they only use it for arrays.
    A vector and array syntax is virtually the same using [].

    Regards,

    Paul McKenzie

  3. #3
    Join Date
    Feb 2013
    Posts
    2

    Re: Issue with bubble sorting vectors

    Thank you very much for the help. Your suggestion seems much easier and more efficient, sadly the project specifies that I should make use of two vectors, one containing all the recorded temperatures and the other their corresponding times. So there's no way around using two vectors. Any suggestions on how I can accomplish this?

  4. #4
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Posts
    12,046

    Re: Issue with bubble sorting vectors

    Given those requirements, there's no need to sort. Just iterate the vector and store the highest temperature and the times it was recorded.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center