tyrone 251
tyrone 251

Reputation: 339

Classes and Queue's

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;
};

Upvotes: 0

Views: 228

Answers (1)

HadeS
HadeS

Reputation: 2038

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
}

Upvotes: 1

Related Questions