/*************************************************************************** main.cpp - description ------------------- begin : Wed Oct 23 14:59:46 EDT 2002 copyright : (C) 2002 by Atanas Dimitrov email : adimitro@localhost.localdomain ***************************************************************************/ /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ #include #include #include #include //To get SLEEP(3) (Linux Programmer's Manual) #include const int MAX_QUEUE=3; const int TRUE=1; const int FALSE=0; struct Proc { int prior; char id[4]; }; class ReadyQueue { public: ReadyQueue(void); void enqueue(Proc); Proc serve(void); int isempty(void); int isfull(void); void display(void); private: int queue_in; Proc ready_queue[MAX_QUEUE]; }; ReadyQueue::ReadyQueue() { queue_in=-1; } void ReadyQueue::enqueue(Proc ins_entr) { queue_in++; ready_queue[queue_in].prior = ins_entr.prior; ready_queue[queue_in].id = ins_entr.id; return; } Proc ReadyQueue::serve(void) { Proc ret_entr; ready_queue[0].prior = ret_entr.prior; ready_queue[0].id = ret_entr.id; for (int i=0; i < queue_in; i++) { ready_queue[i].prior = ready_queue[i+1].prior; ready_queue[i].id = ready_queue[i+1].id; } queue_in--; return ret_entr; } int ReadyQueue::isempty(void) { if (queue_in == -1) return TRUE; else return FALSE; } int ReadyQueue::isfull(void) { if (queue_in == MAX_QUEUE - 1) return TRUE; else return FALSE; } void ReadyQueue::display(void) { for (int i=0; i<=queue_in; i++) { cout << "Element " << i << " prior "<> temp_entr.prior; cout << endl; cin.get(); cout << "Enter Id: "; cin >> temp_entr.id; temp_queue.enqueue(temp_entr); temp_queue.display(); } cout << "Taking out now...\n"; int k=0; for (int b=0; b <=2; b++) { temp_queue.display(); temp_entr=temp_queue.serve(); cout << k << "\n"; cout << "SNIP\n"; k++; } return 0; }