title: Loop that creates doubles and insert them into sorted array, in C
body: <p>Suppose I have a set of sorted doubles.</p>
  
  <pre><code>{ 0.124, 4.567, 12.3 }
  </code></pre>
  
  <p>A positive, non-zero double is created by another part of the code, and needs to be inserted into this set while keeping it sorted. For example, if the created double is <code>7.56</code>, the final result is,</p>
  
  <pre><code>{ 0.124, 4.567, 7.56, 12.3 }
  </code></pre>
  
  <p>In my code, this "create double and insert in sorted set" process is then repeated a great number of times. Possibly 500k to 1 million times. I don't know how many doubles will be created in total exactly, but I know the upper bound.</p>
  
  <p><strong>Attempt</strong></p>
  
  <p>My naive first approach was to create an array with length = upper bound and fill it with zeros, then adding the initial set of doubles to it ("add" = replace a 0 valued entry with the double). Whenever a double is created, I add it to the array and do an insertion sort, which I read is good for sorting ordered arrays.</p>
  
  <p><strong>Question</strong></p>
  
  <p>I have a feeling running 500k to 1 million insertion slots will be a serious performance issue. (or am I wrong?) Is there a more efficient data structure and/or algorithm for doing this in C?</p>
  
  <p><strong>Edit:</strong></p>
  
  <p>The reason why I want to keep the set sorted is because after every "create double and insert in sorted set" process, I need to be able to look up the smallest element in that set (and possibly remove it by replacing it with a 0). I thought the best way to do this would be to keep the set sorted.</p>
  
  <p>But if that is not the case, perhaps there is an alternative?</p>