help with array queues ?

hi, im new to code and having a hard time with array queues" priority queues". im trying to Read and processes a "tasks" from the input file line-by-line, create a task object for each task, and place tasks into the appropriate queue. and print them. and i dont know how would i print the information about the task. i think my read file function runs runs for ever. the input file would be. any help is appreciated. thanks
0 100
2 25
4 75
1 50
3 75
#include <iostream>
#include <queue>
#include <fstream>
#include <string>


using namespace std;


const int timeSlice = 50;

struct Task
{

int pID;
int initialPriority;
int currentPriority;
int totalRunTime;
int remainingRunTime;




};

// function prototype
void readFromFile();
void executeALL();
void printQueue();
queue<Task>PriorityQueues[5];
void main()
{


readFromFile();
printQueue();


cin.get();
cin.ignore();
}
//================================================================
// Function: readFromFile
// Description: Reads from file and puts them in the queue of arrays
//
// Arguments:
// None
// Return value:
// NR
//=================================================================
void readFromFile()
{
int pIDIndex = 1;

int totalRunTimeTemp = 0;

ifstream queueFile;

queueFile.open("queue.txt");

while (!queueFile.eof())
{
Task tempTask;
tempTask.pID = pIDIndex;
pIDIndex++;

queueFile >> tempTask.initialPriority;
queueFile >> tempTask.totalRunTime;

tempTask.currentPriority = tempTask.initialPriority;
tempTask.remainingRunTime = tempTask.totalRunTime;

PriorityQueues[tempTask.initialPriority].push(tempTask);
//cout << " it works" << endl;

}

queueFile.close();
//cout<< PriorityQueues[0].size();
}
//================================================================
// Function: printQueue
// Description: prints the queue
//
// Arguments:
// None
// Return value:
// NR
//=================================================================
void printQueue()
{
Task temp1;


for (int i = 0; i < 6; i++)
{

PriorityQueues[i].front();
cout << PriorityQueues[ temp1.currentPriority] << endl;
cout << temp1.initialPriority << endl;

cout << temp1.remainingRunTime << endl;
cout << temp1.totalRunTime << endl;

//printQueue[i]
cout << "hi how are you" << endl;




}
/*while (!PriorityQueues[i].empty())
{





}*/




}
closed account (E0p9LyTq)
queues and priority_queues are not arrays, you can't access the elements in a queue/priority_queue as you do with arrays.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include <iostream>
#include <queue>

struct Task
{
   int pID;
   int initialPriority;
   int currentPriority;
   int totalRunTime;
   int remainingRunTime;
};

void printQueue(std::queue<Task>&);

int main()
{
   std::queue<Task> taskQueue;

   Task temp = { 10, 20, 30, 40, 50 };
   taskQueue.push(temp);

   temp = { 50, 40, 30, 20, 10 };
   taskQueue.push(temp);

   temp = { 100, 200, 500, 357, 98 };
   taskQueue.push(temp);

   temp = { 55, 45, 101, 12, 1002 };
   taskQueue.push(temp);

   printQueue(taskQueue);
}


void printQueue(std::queue<Task>& taskQueue)
{
   Task temp;

   while (!taskQueue.empty())
   {
      temp = taskQueue.front();

      std::cout << temp.pID << ", "
         << temp.initialPriority << ", "
         << temp.currentPriority << ", "
         << temp.totalRunTime << ", "
         << temp.remainingRunTime << "\n";

      taskQueue.pop();
   }
}



PLEASE learn to use code tags, it makes reading your source much easier.
http://www.cplusplus.com/articles/jEywvCM9/
Last edited on
thanks for the help
Topic archived. No new replies allowed.