Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CAN'T FIGURE IT -- structs on a linked list

Status
Not open for further replies.

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~

 

Hi,

Didn't look at the code but if you're using C++ why not take advantage of CObject and CArrays. Create an object instead of the structs and use CArray instead of a linked list. Your above code is C not C++.

Just trying to help,

Some Dude
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top