0

I am trying to figure out how to work with Queues and Classes.

How can i insert information into this class with a queue?

I created the queue queue<Processes> PrinterDevices

How do i go about insert stuff on this queue into a class or reading from it?

class Processes
{
    public:
        void setPID (int a)
        {
            PID = a;
        }
        int retrievePID()
        {
            return PID;
        }
        void setFilename (string input)
        {
            Filename = input;
        }
        string retrieveFilename()
        {
            return Filename;
        }
        void setMemstart (int a)
        {
            Memstart = a;
        }
        int retrieveMemstart()
        {
            return Memstart;
        }
        void setRW (char a)
        {
            rw = a;
        }
        int retrieveRW()
        {
            return rw;
        }
        void setFilelength (string input)
        {
            Filelength = input;
        }
        string retrieveFilelength()
        {
            return Filelength;
        }
    private:
        int PID;
        string Filename;
        int Memstart;
        char rw;
        string Filelength;
};
tyrone 251
  • 355
  • 1
  • 4
  • 14
  • question not clear.. please expalin elaborately... – Santosh Sahu Mar 10 '14 at 05:27
  • Basically i want to insert the variables PID/Filename/MemStart/RW/File length into a queue, and print them. How do i do this with a class? – tyrone 251 Mar 10 '14 at 05:28
  • Iterating over a queue is not possible because it provides a minimal interface. See the below link for the complete description. "How to iterate over a priority_queue?" So I would prescribe you to provide stl:: deques which will help your work. – Santosh Sahu Mar 10 '14 at 05:50

1 Answers1

1
queue<Processes> PrinterDevices;
Processess obj;
//Populate object through setter methods

To add this object to queue PrinterDevices

`PrinterDevices.push(obj);`

Similarly you can create more object.. To traverse...

while(!PrinterDevices.empty())
{
      Processes obj = PrinterDevices.front();
         //Add code to use obj;
      PrinterDevices.pop();//Remove the object from queue which is already used above
}
HadeS
  • 2,020
  • 19
  • 36
  • I create a copy of my queue when i print it. But i need to use queue for my assignment. – tyrone 251 Mar 10 '14 at 05:51
  • So if you don't want to retain the objects you are storing 'front()' and `pop()` can be used to traverse the list...Look for the changes once I have edited the code above – HadeS Mar 10 '14 at 05:57
  • got it. Now how do i add to certain things such as setpid or or setfilename in my class? – tyrone 251 Mar 10 '14 at 06:16
  • `obj.setFilename ("filename.txt");` and call other setter methods...finally call `PrinterDevices.push(obj)` to add object to queue... – HadeS Mar 10 '14 at 06:21
  • HadeS How would i print that object after i added it into the queue? – tyrone 251 Mar 10 '14 at 07:19