Closed Thread
Results 1 to 4 of 4

Thread: creating a Linked Queue class?

  1. #1
    TshingY is offline Newbie
    Join Date
    Apr 2009
    Posts
    1
    Rep Power
    0

    creating a Linked Queue class?

    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;   
        }
      }
    }
    Last edited by WingedPanther; 04-13-2009 at 05:37 PM. Reason: add code tags (the # button)

  2. CODECALL Circuit advertisement
    Join Date
    Always
    Posts
    Many

     
  3. #2
    Join Date
    Jul 2006
    Posts
    16,478
    Blog Entries
    75
    Rep Power
    143

    Re: creating a Linked Queue class?

    Here's a linked-list based queue in C++, it may help: ADTs: Stacks and Queues Part 2: Using Lists
    Programming is a branch of mathematics.
    My CodeCall Blog | My Personal Blog

  4. #3
    Join Date
    Mar 2009
    Posts
    1,375
    Rep Power
    24

    Re: creating a Linked Queue class?

    So your class would have behaviour of both LinkedList and Queue? First of all, would it be better to make it generic? My guess is yes.

    Here are the generic classes:
    LinkedList(T) Class (System.Collections.Generic)
    Queue(T) Class (System.Collections.Generic)

    I could offer making the whole class for you, if you really need it. I just do not know how to make it from your prototype. Let me know then.

    Regards,
    Arek Bulski

  5. #4
    AlanQ's Avatar
    AlanQ is offline Newbie
    Join Date
    Apr 2009
    Location
    Las Vegas
    Posts
    17
    Rep Power
    0

    Re: creating a Linked Queue class?

    I needed that too, Thanks Arek.

Closed Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Creating objects at runtime using the class name
    By rhossis in forum PHP Development
    Replies: 1
    Last Post: 02-01-2011, 09:46 AM
  2. Beginner Tutorial: Creating a simple class with methods
    By mr mike in forum Ruby on RailsTutorials
    Replies: 0
    Last Post: 01-03-2011, 08:52 PM
  3. Creating a linked list in C
    By DarkLordoftheMonkeys in forum C and C++
    Replies: 8
    Last Post: 01-20-2010, 05:01 PM
  4. FIXED - Problems creating instance of class
    By jacksh1rt in forum Java Help
    Replies: 0
    Last Post: 05-05-2009, 02:33 PM
  5. VS2008 C# Sequential Lists: The Queue And Stack Class
    By Jordan in forum CSharp Tutorials
    Replies: 5
    Last Post: 05-26-2008, 09:43 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts