0

I have two problems, first the below code is quitting randomly because of a memory or uninitialized place error, I just can't see it. second, I'm not sure that the algorithm is correct. (The algorithm is suppose to simulate the Hanbury Brown Twiss photonics experiment for anyone who cares)

The vectors are made up of linearly increasing time stamps, where the stop signal is delayed by 180 seconds, if the i_th start signal is less than the i_th stop signal, the timer starts, ignoring all start signals until the timer meets a stop signal, and vica versa, if the timer is stopped, all stops should be ignored until a start is registered. The code should then bucket sort the time difference between these start/stops.

-If there is a name for this kind of sort please post it below.

The below code takes these filled vectors and tries to simulate this process. but I cant figure out what wrong with the memory issues before I get back to fixing the algorithm.

this is the code I have that doesn't work all the time, it works for start/stop vectors smaller than 10,000 double, but I need it to iterate through up to 100,000 doubles.

   while( starts.size() > 5 && stops.size() > 5 ){
      if( start.at(0) >= stop.at(0) ){
         thisStart = starts.at(0);
      }
      j=0;
      while( stops.at(j) <= starts.at(0) ){
         j++;
      }
      stops.erase(stops.begin(), stops.begin() + j + 1 );
      thisStop = stops.at(0);
      j=0;
      while( starts.at(j) <= thisStop){
         j++;
      }
      starts.erase(starts.begin(), starts.begin() + j+1 );
      bucketSort(thisStop - thisStart, bins, &counts);
   }
4

1 回答 1

0
while( stops.at(j) <= starts.at(0) ){
         j++;
      }

如果没有找到stops小于或等于的元素,此循环将超出范围starts[0]。将out_of_range抛出异常,这at()就是应该做的。我不知道这是否是你的问题,因为你没有具体说明你得到什么样的错误,但这肯定是要寻找的东西。

您可能希望有这样的条件:

while (j < stops.size() && stops[j] <= starts[0]) { ... }
于 2012-07-10T09:28:50.523 回答