-
February 12th, 2013, 11:30 AM
#1
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
-
February 12th, 2013, 12:49 PM
#2
Re: Issue with bubble sorting vectors
Originally Posted by Grape Wizard
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
-
February 12th, 2013, 01:03 PM
#3
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?
-
February 12th, 2013, 01:10 PM
#4
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|