hi,
im working with the queue class but not allowed 2 use the collections namespace, ok thats fine. paitent is the name for objects i want to queue. heres my paitent class

public class paitent
        {
            private string name;
            private string NHSW;
            private paitent next;
        }
        public string name
        {
            get { return name; }
            set { name value; }
        }
        public string NHSNnumber
        {
            get {return NHSN;}
            set { NHSN value; }
        }
        public paitent next
        {
            ///////////// here i want to combine name and NHSNnumber\\\\\\\\\\\
        }

im thinking i need a for loop. does any one know of a good web page where i can see some
queues to help.

any suggestions would be awesome, thanks

Recommended Answers

All 6 Replies

Your queue class should be independent of your patient class. A patient doesn't have a Queue, a Queue contains a patient.

What does a queue need? A way to add members to the queue, a way to remove members from the queue and a way to see if there is anyone in the queue. Implement those methods and you'll have your Queue class.

Use the generic Queue type available in .NET
Something like:

Queue<patient> PatientsWaiting = new Queue<patient>();
patient P = new patient();
P.Name = "Smith";
PatientsWaiting.Enqueue(P);

Use the generic Queue type available in .NET

You didn't read the original problem, i.e. the line that says "I'm not allowed to use the collections namespace".

Yes, I know, my bad.
I was in fact referring to your answer, to separate the patient class from the Queue class. Thought mayby an small snippet on how it can be done, might help.

thanks for responding fellas. i have the paitent class sorted and im sure it will work. i was just hoping someone had came across a web page, but ill see how we go

so im just going to use stack with my queue. the only thing im having problems with is with enqueue.im tryng to gt new patients on the stack,iv tried a few ways to do it but same errors. i cant see any other problems other than that, but if there are let me know and ill debug. thanks heaps guys

public class patient
        {
            private string name;
            private string NHSN;
            private string urgency;

            private patient next()
            {}
            private patient next(string name, string NHSN, string urgency)
            {
                name = name;
                NHSN = NHSNnumber;
                urgency = urgency;
        }
        public string name
        {
            get { return name; }
            set { name value; }
        }
        public string NHSNnumber
        {
            get {return NHSN;}
            set { NHSN value; }
        }
            public string urgency
            { 
                get {return urgency;}
                set {urgency value;}
            }
      }
        public class Queue
        {
            private patient first;
            private patient last;
            public Queue patientqueue = new Queue();
            public Stack patientstack = new Stack();
                }
             public void enqueue(patient);////////////here it is////////////////////
                 
        //static void Main(string[] args)
        {
            if(TextBox3.Text == "U")
            {
            patient U = new patient(textBox1.Text + textBox2.Text);
            }  
           if(TextBox3.Text == "N")
            {
            patient N = new patient(textBox1.Text + textBox2.Text);
            }
            Queue queue = new Queue();
            Queue.patientqueue.enqueue(U);
            Queue.patientqueue.enqueue(N);
            Queue.enqueue(Queue.patientqueue);
             }
            public patient dequeue();
              {
            patient newpatient = new patient();
            patient patientnext = new patient(); // next  in line examine
            
            while (patientp.Count != 0)
            {

    if (patientstack.Count != 0)
    {
      if (patientp.Count > 0) 
        {
          patientnext = (patient)patientp.Peek(); 
        }
        if (patientnext.urgency == "U")
        { 
         newpatient = (patient)patientp.Dequeue();
         listBox1.ToString((textbox1.Text + textBox2.Text + textBox3.Text), newpatient.name);
        if (patientnext.urgency == "N")
        { 
            newpatient = (patient)patientnext.Pop();
           listBox1.ToString((textbox1.Text + textBox2.Text + textBox3.Text), newpatient.name);
        }
      }
    if (patientnext.Count == 0)
          {
            newpatient = (patient)patientp.Dequeue();
       
            if (patientp.Count > 0)
            { 
                patientnext = (patient)patientp.Peek();
            }
            if (newpatient.urgency == "U")
            {
                listBox1.ToString((textbox1.Text + textBox2.Text + textBox3.Text), newpatient.name);
            }
            if ((newpatient.urgency == "N") && (patientnext.urgency == "N"))
            {
                listBox1.ToString((textbox1.Text + textBox2.Text + textBox3.Text), newpatient.name);
            }
            if ((newpatient.urgency == "N") && 
               (patientnext.urgency == "U"))
            {
                patientnext.Push(newpatient);
                listBox1.ToString((textbox1.Text + textBox2.Text + textBox3.Text), patientnext.Count.ToString());
                listBox1.ToString((textbox1.Text + textBox2.Text + textBox3.Text), newpatient.name + NHSN);
            
                // get next
              newpatient = (patient)newpatient.Dequeue();
              listBox1.ToString((textbox1.Text + textBox2.Text + textBox3.Text), newpatient.name);                
            }
               }
              public int length();
              {
              new length = new Count;  
               }
               public bool isEmpty();

               if (enqueue.Count < 0)
                {
                  isEmpty == true;
                }    
             }
       public void button1_Click(object sender,EventArgs e)
        {
        if(textBox1.Text.Trim() != patientp.isEmpty)
        {
            patientp.Enqueue(textBox1.Text.Trim());
            listBox1.Items.Insert(listBox1.Items.length,
            "Added patient: " + textBox1.Text.Trim() + " At " + DateTime.Now.ToString());
        }
        else
        {
            listBox1.show("Empty Value Cannot be Added","QueueDemo");
        }
    }
    public void button2_Click(object sender, EventArgs e)
    {
        try
        {
           listBox1.show("Removed patient "  + 

            patientp.Dequeue().ToString());
            listBox1.Items.RemoveAt(0);
        }
        catch(Exception ex)
        {
            listBox1.show("Error: " + ex.Message); 
        }
public void button3_Click(object sender, EventArgs e)
{
    patient newpatient = new patient();
    Queue copyofpatientp = new Queue();
    copyofpaitenp = (Queue)patientp.Clone();
    listBox1.WriteLine(" ");
    listBox1.Show("View the queue using a copy");
    do
    {
       tempCustomer = (BankCustomer)copyoflocalQueue.Dequeue();
        listbox1.Items.add("Name: " + newpatient.name + ",number: " + newpatient.NHSN + 
                          ",  urgency: " + 
                          newpatient.urgency.ToString() + 
    } while (copyofpatientp.Count != 0);
}
      static void main()
    {
        Application.Run(new patientp());
    }
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.