Guest_imported
New member
- Jan 1, 1970
- 0
hey all--
i'm new to c++ (as the difficulties below will undoubtedly prove) and would GREATLY appreciate any/all help i can get...
i'm trying to set up and manipulate several linked lists, each containing structs as their elements. so ->
#include <list>
using namespace std;
struct Process {
string PID;
int arrivalTime;
....
};
list <Process> newQ;
list <Process> readyQ;
list <Process> diskQ;
list <Process> runQ;
list <Process> exitQ;
list<Process>::iterator newQPtr;
list<Process>::iterator readyQPtr;
list<Process>::iterator diskQPtr;
list<Process>::iterator runQPtr;
list<Process>::iterator exitQPtr;
the code compiles fine...first I populate the newQ with Processes, and that works... but i get indistinguishable run-time errors when i try something akin to
for(newQPtr=newQ.begin(); newQPtr!=newQ.end(); newQPtr++)
{
if(newQPtr->arrivalTime == time)
{
readyQ.push_back(*newQPtr);
newQ.erase(newQPtr);
}
}
(basically trying to take a Process struct off the newQ and place it on the readyQ)
does anyone have any idea what i'm doing wrong here? is the problem with the iterator? if so, what kind of pointer should i be using? i need to be able to iterate through the various lists, taking nodes off one list and placing them on another.
thanks in advance~
i'm new to c++ (as the difficulties below will undoubtedly prove) and would GREATLY appreciate any/all help i can get...
i'm trying to set up and manipulate several linked lists, each containing structs as their elements. so ->
#include <list>
using namespace std;
struct Process {
string PID;
int arrivalTime;
....
};
list <Process> newQ;
list <Process> readyQ;
list <Process> diskQ;
list <Process> runQ;
list <Process> exitQ;
list<Process>::iterator newQPtr;
list<Process>::iterator readyQPtr;
list<Process>::iterator diskQPtr;
list<Process>::iterator runQPtr;
list<Process>::iterator exitQPtr;
the code compiles fine...first I populate the newQ with Processes, and that works... but i get indistinguishable run-time errors when i try something akin to
for(newQPtr=newQ.begin(); newQPtr!=newQ.end(); newQPtr++)
{
if(newQPtr->arrivalTime == time)
{
readyQ.push_back(*newQPtr);
newQ.erase(newQPtr);
}
}
(basically trying to take a Process struct off the newQ and place it on the readyQ)
does anyone have any idea what i'm doing wrong here? is the problem with the iterator? if so, what kind of pointer should i be using? i need to be able to iterate through the various lists, taking nodes off one list and placing them on another.
thanks in advance~