<p>Can someone please help me, i can\'t figure this one out.<br /><br />Implemen
ID: 3640395 • Letter: #
Question
<p>Can someone please help me, i can't figure this one out.<br /><br />Implement the following specifications for an integer function in the client program that returns the number of items in a queue. Queue is unchanged. <br /><br />Int GetLength(QueType queue)<br />Function: Determine number of items in queue<br />Precondition: Queue is initialized<br />Post Conditions: queue is unchanged. Function value = number of items in queue</p>Explanation / Answer
Hi, my friend in queues we must have a counter to know where we r if we r using arrays anyway u didn`t mention what type of queue u have and if u r using stl this si another story but here is the class queuue hope this will help u PLEASE RATE #ifndef __QueueClassH__ #define __QueueClassH__ #include // For error-checking purposes //------------------------------------------------- // Main structure of Queue Class: //------------------------------------------------- template class Queue { public: Queue(int MaxSize=500); Queue(const Queue &OtherQueue); ~Queue(void); void Enqueue(const Elem &Item); // Adds Item to Queue end Elem Dequeue(void); // Returns Item from Queue inline int ElemNum(void); // Returns Number of Elements protected: Elem *Data; // The actual Data array const int MAX_NUM; // The actual spaces will be one more than this int Beginning, // Numbered location of the start and end End; // Instead of calculating the number of elements, using this variable // is much more convenient. int ElemCount; }; //------------------------------------------------- // Implementation of Queue Class: //------------------------------------------------- // Queue Constructor function template Queue::Queue(int MaxSize) : MAX_NUM( MaxSize ) // Initialize the constant { // This extra space added will allow us to distinguish between // the Beginning and the End locations. Data = new Elem[MAX_NUM + 1]; Beginning = 0; End = 0; ElemCount = 0; } // Queue Copy Constructor function template Queue::Queue(const Queue &OtherQueue) : MAX_NUM( OtherQueue.MAX_NUM ) // Initialize the constant { Beginning = OtherQueue.Beginning; End = OtherQueue.End; ElemCount = OtherQueue.ElemCount; Data = new Elem[MAX_NUM + 1]; for (int i = 0; i 0 ); Elem ReturnValue = Data[ Beginning++ ]; --ElemCount; // Check for wrap-around if (Beginning > MAX_NUM) Beginning -= (MAX_NUM + 1); return ReturnValue; } // ElemNum() function template inline int Queue::ElemNum(void) { return ElemCount; } #endif /*__QueueClassH__*/Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.