本文整理汇总了C++中Sim::getTimeRemain方法的典型用法代码示例。如果您正苦于以下问题:C++ Sim::getTimeRemain方法的具体用法?C++ Sim::getTimeRemain怎么用?C++ Sim::getTimeRemain使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Sim
的用法示例。
在下文中一共展示了Sim::getTimeRemain方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: pp
// Preemptive Priority (PP)
void pp(Sim* p, int size)
{
int tempWait = 0, minTurn = p[0].getTurnTime(), maxTurn = 0, turnT = 0, minInitial = p[0].getITime(),
maxInitial = 0, initialT = 0, minWait = p[0].getWaitTime(), maxWait = 0, totalW = 0;
vector <Sim> arrived; //vector to store processes that has arrived
int counter = 0;
int store = 0;
bool firstTime = true;
elapsedTime = 0;
cout << "\n\n\nPreemptive-Priority | Send Processes to CPU and run: \n";
//push process into the vector if the arrival time is 0
for (int i = 0; i < size; i++)
{
if (p[i].getATime() == 0)
{
arrived.push_back(p[i]);
}
}
//Sort "arrived" by priority
sortPriority(arrived);
while(counter != size)
{
int checkArrival;
int timeShortest = 8000;
bool found = false;
Sim temp = arrived[0];
for (int i = 0; i < size; i++)
{
checkArrival = arrived[0].getTimeRemain() + elapsedTime;
if (checkArrival > p[i].getATime())
{
if(p[i].getATime() < timeShortest)
{
timeShortest = p[i].getATime();
}
found = true;
}
}
if(found == true)
{
arrived[0].setTimeRemain(elapsedTime - arrived[0].getcTime()); // set the remain time for current process
elapsedTime = elapsedTime - arrived[0].getTimeRemain();
for(int i = 0; i < size; i ++)
{
if(p[i].getATime() == timeShortest)
{
arrived.push_back(p[i]);
}
}
sortPriority(arrived);
}
else // the process has terminated before any other process entered
{
arrived[0].setTimeRemain(0);
temp = arrived[0];
arrived.erase(arrived.begin());
sortPriority(arrived);
elapsedTime+=temp.getTimeRemain(); // final elapsed time after this process terminates
temp.setTurnTime(elapsedTime);
printTerminate(elapsedTime, temp.getpId(), temp.getTurnTime(), temp.getWaitTime());
counter++;
}
if (!firstTime && !arrived.empty( ))
{
elapsedTime = totalElapsedTime(elapsedTime);
printContextSwitch(elapsedTime, temp.getpId(), arrived[0].getpId());
elapsedTime = totalElapsedTime(elapsedTime);
}
firstTime = false;
}
}