This is my first time asking something on this site, so if I breach any sort of etiquette, let me know.
I am really new to linked lists and thought that implementing them using the list
datatype would be pretty straightforward, but it seems I'm trying to do something weird with them.
I have created a list
called "eventList" into which I want to put a series of struct
s called "entry", and then I wish to put several "eventList"s into an array called "processList".
My issue is that the bit of code
processList[pid].push_front(newEntry);
seems to give me an error. Is there something obviously wrong with what I'm doing?
Here is the code:
#include <iostream>
#include <fstream>
#include <list>
#include <string>
#include <array>
using namespace std;
struct entry {
int eTime;
string eType;
int pid;
};
int main(){
ifstream infile;
string comm;
int num;
entry newEntry;
list<entry> eventList;
array<list<entry>, 1024> processList;
infile.open("input00.txt");
if(infile.is_open()){
while(!infile.eof()){
int pid = -1;
string eTy;
int eTi;
infile >> eTy;
infile >> eTi;
if(eTy == "NEW"){
pid++;
cout << "DB: Process " << pid << endl;
}
else{
newEntry.pid = pid;
newEntry.eType = eTy;
cout << "Type: " << newEntry.eType << " | ";
newEntry.eTime = eTi;
cout << "Time: " << newEntry.eTime << endl;
processList[pid].push_front(newEntry);
//processList[pid] = eventList; <- realized that that wouldn't work fairly quickly
}
}
}
else {
cout << "Sorry, that file doesn't work. :[" <<endl;
}
cout << "Original Order:" << endl;
list<entry>::iterator p = eventList.begin();
while(p != eventList.end()){
cout << p->eType << " For " << p->eTime << "\n"; //This comes from http://www.cplusplus.com/forum/beginner/3396/
p++;
}
//cout << "Ordered By Time:\n";
//eventList.sort(); <- commented out, because I can't get it to work. :[
system ("PAUSE");
return 0;
}
I really love that this resource is available, and I hope that I can follow the logic of any answers that come this way. Apologies for the noobishness, and thanks for looking!