title: How would I implement a FCFS processor scheduling simulator?
body: <p>I have a vector of structs, with the structs looking like this:</p>
  
  <pre><code>struct myData{
      int ID;
      int arrivalTime;
      int burstTime;
  };
  </code></pre>
  
  <p>After populating my vector with this data:</p>
  
  <pre><code>1 5 16
  4 7 12
  3 12 4
  2 7 8
  </code></pre>
  
  <p>where each row is an individual struct's ID (arbitrary, doesn't denote order of arrival), arrivalTime and burstTime, how would I use "for" or "while" loops to step through my vector's indices and calculate the data in a way that I could print something like this out?</p>
  
  <pre><code>Time 0  Processor is Idle
  Time 5 Process 1 starts running
  Time 21 Process 2 is running
  Time 29 Process 4 is running
  Time 41 Process 3 is running
  </code></pre>
  
  <p>The way I thought I could do it was to have an integer keep track what the current time is (the current time being the sum of the burst times of processes that have already ran) but I can't seem to figure out an algorithm that accounts for Idle time (when the processor is not doing anything and a new task hasn't arrived yet) as well as keeping track of the other numbers as well. For simplicity's sake I just decided that when two processes arrive at the same time I would process the one with the lower ID number. I know I didn't put much code here to demonstrate what I'm trying to do, but I hope I've explained it fairly clearly. I'm looking for a psuedo-code algorithm solution to this problem, but I wouldn't say no to something that has been coded (In C++?).</p>
  
  <p>As an additional note, in case I wasn't able to convey how I access my data clearly, this:</p>
  
  <pre><code>cout &lt;&lt; structVector[0].ID &lt;&lt; "\n";
  cout &lt;&lt; structVector[0].arrivalTime &lt;&lt; "\n";
  cout &lt;&lt; structVector[0].burstTime &lt;&lt; "\n";
  </code></pre>
  
  <p>would print out</p>
  
  <pre><code>1
  5
  16
  </code></pre>
  
  <p>Any help in psuedo-code or actual code would be GREATLY appreciated!!! After reading this post over a few times I realize I've been pretty generic with the question, but I would love some help just understanding how to calculate this data.</p>