I'm stuck on creating a linked queue class. I am not sure on the properties of the class. Would I need a head, top, and rear property or just a top and rear property? How would I code it to do the Enqueue and Dequeue? Thanks.
Code:using System; using System.Windows.Forms; using System.Collections.Generic; using System.Text; namespace LinkedQueueLib { public class QueueNode { private object data; private QueueNode next; public QueueNode(object dataValue) // Initializing Constructor { this.data = dataValue; this.next = null; } public object Data // Read-only Data Property { get { return this.data; } set { this.data = value; } } public QueueNode Next // Read/Write Next property { get { return this.next; } set { this.next = value; } } } // End class QueueNode //Begin class LinkedQueue public class LinkedQueue { private string name; private int size; private QueueNode front; private QueueNode rear; private QueueNode head; public LinkedQueue() // Default constructor { this.name = "Linked Queue"; this.size = 0; this.head = new QueueNode(null); this.rear = this.head; this.front = this.head; } public LinkedQueue(string nameValue) //Initializing constructor { this.name = nameValue; this.size = 0; this.head = new QueueNode(null); this.rear = this.head; this.front = this.head; } public string Name // Define read/write Name property { get { return this.name; } set { this.name = value; } } public int Size // Define read-only Size property { get { return this.size; } } public bool Empty // Return true (false) if queue is (not) empty { get { return (this.size == 0); } } public void Purge() // Remove all queue datas { while (!this.Empty) this.Dequeue(); } public void Enqueue(object data) // Implement the enqueue operation { QueueNode queueNode = new QueueNode(data); this.rear.Next = queueNode; this.front.Next = this.rear.Next; this.rear = queueNode; this.size++; } public object Dequeue() // Implement the dequeue operation { object data = null; data = this.head.Next.Data; this.head.Next = this.front.Next; this.size--; return data; } } }


LinkBack URL
About LinkBacks




Reply With Quote








Bookmarks
Algorithms and Data Structures
Java tutorials
Algorithms Forum