Click here to Skip to main content
15,846,899 members
Please Sign up or sign in to vote.
2.00/5 (3 votes)
See more:
ok this is all my coding. i dont think length would be all that important to me ill just use count. the only problem im having is with enqueue. it expects class,delegate... to be used but ive tried to do that. im out of ideas hopefully i can solve it but a fresh mind would be good. cheers all

C#
   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);////////////////heres enqueue
                 
        //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());
    } 
;


What happens is the user puts in name and NHSN and then if U or N is put in, stack sorts them.
Posted
Updated 7-Oct-10 2:44am
v4
Comments
PumbaPumba 6-Oct-10 2:15am    
could you please update a clear code snippet?
[no name] 7-Oct-10 16:06pm    
A clear question would be nice...
Dylan Morley 10-Dec-10 11:19am    
I really hope this isn't for the fancy new NHS IT system.

1 solution

Ok, the answer seems simple. Do not use classes Stack or Queue; they are almost useless or at least unsafe for your application. Instead, use generic classes Stack<> and Queue<>. In angular brackets, put actual compile-time type you want to have for element of your Queue or Stack.

If I understand your code, you will use:

C#
Queue<patient> Queue = new Queue<patient>();
Stack<patient> Stack = new Stack<patient>();


Also, do yourself a favor, use standard naming conventions: Patient, not patient, because this is a type name.
 
Share this answer
 
v5
Comments
Sergey Alexandrovich Kryukov 10-Dec-10 14:47pm    
Gosh, this is the most concrete answer? What else do I need to get 5, I wonder? :)
Espen Harlinn 26-Feb-11 10:46am    
Not much - a 5
Sergey Alexandrovich Kryukov 26-Feb-11 13:49pm    
Ha-ha. Thank you Espen. How come you address so old posts?
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900