You are on page 1of 2

//Start Code namespace Queue { using System; /// /// implementation for a First in First out Queue ///

public class Queue { private uint count = 0; private Node front = null; private Node end = null; private Node temp = null; /// /// Test to see if the Queue might be empty. /// public bool empty { get { return(count==0); } } /// /// Number of Items in the Queue. /// public uint Count { get { return count; } } /// /// This function will append to the end of the Queue or /// create The first Node instance. /// /// public void append(object obj) { if(count==0){ front = end = new Node(obj, front); } else { end.Next = new Node(obj, end.Next); end = end.Next; } count++; } /// /// This function will serve from the front of the Queue. Notice /// no deallocation for the Node Class, This is now handled by the /// Garbage Collector. /// public object serve() { temp = front; if(count == 0) throw new Exception("tried to serve from an empty Queue"); front = front.Next; count--;

return temp.Value; } /// /// This function will print everything that is currently in the /// Queue. /// public void printQueue() { temp = front; while(temp != null){ Console.WriteLine("{0}", temp.Value.ToString()); temp = temp.Next; } } } /// /// The Node class holds the object and a pointer to the next /// Node class. ///

You might also like