Ok, i have it working so far... now the next step is to take the data from the node, and put it into a "ready list" according the first number in the text file: text file looks like...
30 4.56667
43 0.56674
57 12.7786
etc...
where the first number represents the arrival time of the process to be sent from the tempList (used to store data from the file) into the "Ready List" and the second number represents how long for that process to stay in the loop iterations (faux CPU). My question is, how do I take the data and put it into the ready list now?
heres the code so far...
Code:
#include <cstdlib>
#include <iostream>
#include <fstream>
using namespace std;
class tempList
{
public:
struct node;
typedef node *nodePtr;
struct node
{
int arrivalTime;
float timeToProcess;
nodePtr link;
};
tempList();
~tempList();
tempList(const tempList& L);
add(int inThing1, float inThing2);
void remove(int toBeRemoved);
void print();
private:
nodePtr head;
};
tempList::tempList()
{
head = NULL;
}
tempList::~tempList()
{
nodePtr p = head;
nodePtr q;
while(p)
{
q=p;
p=p->link;
delete(q);
}
head = NULL;
}
tempList::tempList(const tempList& L)
{
nodePtr orig, copy, q;
if (L.head == NULL)
head = NULL;
else
{
head = new node;
head->link = NULL;
head->arrivalTime = L.head->arrivalTime;
head->timeToProcess = L.head->timeToProcess;
q = head;
orig = L.head->link;
while (orig!=NULL) //more stuff to copy
{
copy = new node;
copy->arrivalTime = orig->arrivalTime;
copy->timeToProcess = orig->timeToProcess;
copy->link = NULL;
q->link = copy;
//advance pointers
orig = orig -> link;
q = copy;
}
}
}
void tempList::print()
{
nodePtr walker;
walker = head;
while (walker != NULL)
{
cout<<walker->arrivalTime<<" "<<walker->timeToProcess<<endl;
walker = walker->link;
}
}
tempList::add(int inThing1, float inThing2)
{
nodePtr p;
p = new node; //allocates
p->link=NULL;
p->arrivalTime = inThing1; //fill the data
p->timeToProcess = inThing2;
p->link = head; //links node into list as the first node
head = p; //resets head
}
void tempList::remove(int toBeRemoved) //removes from the back of the list...
{
nodePtr walker, shadow;
walker = head;
bool found = 0;
while ((walker != NULL) && !found)
{
if (walker->arrivalTime == toBeRemoved)
found = 1;
else //advance pointers because value has not been found
{
shadow = walker;
walker = walker->link;
}
}
if (walker == NULL)
cout<<"Not in list"<<endl;
else
{
shadow->link = walker->link;
delete (walker);
}
}
void getData();
void processData();
int main()
{
getData();
processData();
//now process the data and run simulation
return 0;
}
void getData()
{
tempList myList;
ifstream inFile;
int arrival;
float timeProcess;
inFile.open("times.txt", ios::out);
if (!inFile)
{
cout<<"Error opening file"<<endl;
exit(1);
}
while(inFile>>arrival>>timeProcess)
{
myList.add(arrival, timeProcess);
}
myList.print();
}
void processData()
{