473,412 Members | 3,343 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,412 software developers and data experts.

need help with Queue program

28
I need the definitions of the method copyQueue, the default constructor, and the copy constructor folr the class LinkedQueueClass.


Expand|Select|Wrap|Line Numbers
  1. This is my default constructor method
  2.  
  3. //default constructor
  4.     public LinkedQueueClass()
  5.     {
  6.         queueFront = null;
  7.         queueRear = null;
  8.    }
Nov 9 '06 #1
5 6780
r035198x
13,262 8TB
I need the definitions of the method copyQueue, the default constructor, and the copy constructor folr the class LinkedQueueClass.


Expand|Select|Wrap|Line Numbers
  1. This is my default constructor method
  2.  
  3. //default constructor
  4. public LinkedQueueClass()
  5. {
  6. queueFront = null;
  7. queueRear = null;
  8. }
Depends on the structure of the rest of your LinkedQueueClass. eg are you using a vector, array, ArrayList
eg
Expand|Select|Wrap|Line Numbers
  1.  public LinkedQueueClass(LinkedQueueClass list) { 
  2.   queueFront = list.getFront();
  3.   queueRear = list.getRear();
  4.   list = list.getList(); 
  5. }
  6.  
Nov 9 '06 #2
satan
28
This is the entire class

Expand|Select|Wrap|Line Numbers
  1. public class LinkedQueueClass1
  2. {
  3.           //Definition of the node
  4.     protected class QueueNode
  5.     {
  6.         DataElement info;
  7.         QueueNode link;
  8.     }
  9.  
  10.     private QueueNode queueFront; //reference variable to the
  11.                                   //first element of the queue
  12.     private QueueNode queueRear;  //reference variable to the
  13.                                   //last element of the queue
  14.         //default constructor
  15.     public LinkedQueueClass()
  16.     {
  17.         queueFront = null;
  18.         queueRear = null;
  19.     }
  20.  
  21.  
  22.         //copy constructor
  23.     public LinkedQueueClass(LinkedQueueClass otherQueue)
  24.     {
  25.        NEED HELP HERE
  26.     }
  27. //end copy constructor
  28.  
  29.         //Method to initialize the queue to an empty state.
  30.         //Postcondition: queueFront = null; queueRear = null
  31.      public void initializeQueue()
  32.      {
  33.           queueFront = null;
  34.           queueRear = null;
  35.      }
  36.  
  37.         //Method to determine whether the queue is empty.
  38.         //Postcondition: Returns true if the queue is empty;
  39.         //               otherwise, returns false.
  40.      public boolean isEmptyQueue()
  41.      {
  42.           return (queueFront == null);
  43.      }
  44.  
  45.  
  46.         //Method to determine whether the queue is full.
  47.         //Postcondition: Returns true if the queue is full;
  48.         //               otherwise, returns false.
  49.      public boolean isFullQueue()
  50.      {
  51.           return false;
  52.      }
  53.  
  54.         //Method to return the first element of the queue.
  55.         //Precondition: The queue exists and is not empty.
  56.         //Postcondition: If the queue is empty, the method throws
  57.         //               QueueUnderflowException; otherwise, a
  58.         //               reference to a copy of the first element
  59.         //               of the queue is returned.
  60.      public DataElement front() throws QueueUnderflowException
  61.      {
  62.           if(isEmptyQueue())
  63.              throw new QueueUnderflowException();
  64.  
  65.           DataElement temp = queueFront.info.getCopy();
  66.           return temp;
  67.      }
  68.  
  69.         //Method to return the last element of the queue.
  70.         //Precondition: The queue exists and is not empty.
  71.         //Postcondition: If the queue is empty, the method throws
  72.         //               QueueUnderflowException; otherwise, a
  73.         //               reference to a copy of the last element
  74.         //               of the queue is returned.
  75.      public DataElement back() throws QueueUnderflowException
  76.      {
  77.           if(isEmptyQueue())
  78.              throw new QueueUnderflowException();
  79.  
  80.           DataElement temp = queueRear.info.getCopy();
  81.           return temp;
  82.      }
  83.  
  84.  
  85.         //Method to add queueElement to the queue.
  86.         //Precondition: The queue exists.
  87.         //Postcondition: The queue is changed and queueElement
  88.         //               is added to the queue.
  89.      public void addQueue(DataElement newElement)
  90.      {
  91.           QueueNode newNode;
  92.  
  93.           newNode = new QueueNode();  //create the node
  94.  
  95.           newNode.info = newElement.getCopy();  //store the info
  96.           newNode.link = null;   //initialize the link field to null
  97.  
  98.           if(queueFront == null) //if initially the queue is empty
  99.           {
  100.              queueFront = newNode;
  101.              queueRear = newNode;
  102.           }
  103.           else   //add newNode at the end
  104.           {
  105.              queueRear.link = newNode;
  106.              queueRear = queueRear.link;
  107.           }
  108.      }//end addQueue
  109.  
  110.  
  111.         //Method to remove the first element of the queue.
  112.         //Precondition: The queue exists and is not empty.
  113.         //Postcondition: The queue is changed and the first
  114.         //               element is removed from the queue.
  115.      public void deleteQueue() throws QueueUnderflowException
  116.      {
  117.           if(isEmptyQueue())
  118.              throw new QueueUnderflowException();
  119.  
  120.           queueFront = queueFront.link; //advance queueFront
  121.  
  122.           if(queueFront == null)  //if after deletion the queue is
  123.              queueRear = null;  //empty, set queueRear to null
  124.      } //end deleteQueue
  125.  
  126.  
  127.         //Method to make a copy of otherQueue.
  128.         //Postcondition: A copy of otherQueue is created and
  129.         //               assigned to this queue.
  130.     public void copyQueue(LinkedQueueClass otherQueue)
  131.     {
  132.       NEED HELP HERE
  133.     }
  134. }
Nov 9 '06 #3
r035198x
13,262 8TB
Expand|Select|Wrap|Line Numbers
  1.  
  2.  //Your queue has only 2 elements so just copy them
  3.     public LinkedQueueClass(LinkedQueueClass otherQueue)
  4.     {
  5.        queueFront = otherQueue.queueFront;
  6.        queueRear = otherQueue.queueRear;
  7.     } 
  8.  
  9.  
  10. public void copyQueue(LinkedQueueClass otherQueue)
  11.     {
  12.       //same as copy constructor
  13.       queueFront = otherQueue.queueFront;
  14.       queueRear = otherQueue.queueRear;
  15.     }
  16.  
Nov 9 '06 #4
r035198x
13,262 8TB
Comments on your Linked Queue

1) Maybe include the size for easier reference
Expand|Select|Wrap|Line Numbers
  1.  
  2. public class LinkedQueueClass {
  3.   private QueueNode queueFront; //reference variable to the
  4.   private QueueNode queueRear;  
  5.   private int size;
  6.  
  7.   public LinkedQueue() {
  8.     size = 0;
  9.     queueFront = null;
  10.     queueRear= null;
  11.   }
  12. ....
  13.  
2) Consider implementing Queue interface from java library
Nov 9 '06 #5
satan
28
Comments on your Linked Queue

1) Maybe include the size for easier reference
Expand|Select|Wrap|Line Numbers
  1.  
  2. public class LinkedQueueClass {
  3.   private QueueNode queueFront; //reference variable to the
  4.   private QueueNode queueRear;  
  5.   private int size;
  6.  
  7.   public LinkedQueue() {
  8.     size = 0;
  9.     queueFront = null;
  10.     queueRear= null;
  11.   }
  12. ....
  13.  
2) Consider implementing Queue interface from java library



I'am on it, i will let u know if it's compiling. Thanks
Nov 9 '06 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Jeff | last post by:
IDE: VS .NET 2003 OS: XP pro sp2 I'm developing a server application, clients will connect to it over the net and start different tasks.... When people sends a command to the program, the...
1
by: Ty Moffett | last post by:
I am trying to write a little app that will perform unattended installations of various software packages. I have a text file, each line is a string containing the complete command to start a...
19
by: ern | last post by:
I need a FIFO queue of size 20, to keep track of a running average. Once the queue is full with 20 values, I want to take the sum/20 = AVERAGE. Then when a new value comes in, I want: (Old Sum...
3
by: Kceiw | last post by:
Dear all, When I use #include "queue.h", I can't link it. The error message follows: Linking... G:\Projects\Datastructure\Queue\Debug\main.o(.text+0x136): In function `main':...
0
by: rokuingh | last post by:
ok, so i've been working on this one for quite a while, and the code is very big so i'm just going to give the relevant parts. this is a program that builds polymers (chemical structures of repeated...
7
by: RobKinney1 | last post by:
Here is another question we have been meaning to post for a long time. My colleague is literally pulling chunks of hair out of his head right now. We have a logging class. This class is...
5
by: shanknbake | last post by:
Here is my code. I've noted where the program crashes. I'm doing this program as a project for school. //cqueue.h file //HEADER FILE http://rafb.net/paste/results/Nh0aLB77.html...
5
Rooro
by: Rooro | last post by:
Hello everyone i'm working on : " Familiar childhood games such as hide and Go Seek and Tag involve determining the player who is to be "It". One method has the players stand in a circle...
5
by: bean330 | last post by:
Hey, I'm somewhat new to C# and I need a little help, please! I'm selecting a bunch of records, setting properties on a COM executable and then calling a method on that executable to run. I...
1
by: curiousEngine | last post by:
how to make provision of a dynamic array say of size 5 with each slot holding a structure of type passenger? /* * Labsheet Queues Question 1 Implement a program that shows a queue of people...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.