+ Reply to Thread
Results 1 to 4 of 4

Thread: creating a Linked Queue class?

  1. #1
    Newbie TshingY is an unknown quantity at this point
    Join Date
    Apr 2009
    Posts
    1

    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 07:37 PM. Reason: add code tags (the # button)

  2. #2
    Super Moderator WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther's Avatar
    Join Date
    Jul 2006
    Age
    36
    Posts
    11,680
    Blog Entries
    57

    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
    CodeCall Blog | CodeCall Wiki | Shareware
    Programming is a branch of mathematics.
    My CodeCall Blog | My Personal Blog

  3. #3
    Guru ArekBulski is just really nice ArekBulski is just really nice ArekBulski is just really nice ArekBulski is just really nice ArekBulski is just really nice ArekBulski's Avatar
    Join Date
    Mar 2009
    Posts
    1,374

    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

  4. #4
    Newbie AlanQ has a little shameless behaviour in the past AlanQ's Avatar
    Join Date
    Apr 2009
    Location
    Las Vegas
    Posts
    16

    Re: creating a Linked Queue class?

    I needed that too, Thanks Arek.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

     

Similar Threads

  1. Tutorial: Starting C# with C# 2008 Express Edition
    By Jordan in forum CSharp Tutorials
    Replies: 20
    Last Post: 07-27-2009, 04:45 AM
  2. Help with FIFO QUEUE
    By ghost305 in forum C and C++
    Replies: 6
    Last Post: 04-03-2009, 06:08 AM
  3. PHP 5 and OOP
    By Jordan in forum PHP Tutorials
    Replies: 11
    Last Post: 09-22-2008, 01:58 AM
  4. VS2008 C# Sequential Lists: The Queue And Stack Class
    By Jordan in forum CSharp Tutorials
    Replies: 5
    Last Post: 05-26-2008, 11:43 AM
  5. Creating a Class in Visual Studios.Net (Visual Basic Section)
    By dream in forum Visual Basic Programming
    Replies: 11
    Last Post: 05-12-2008, 02:47 PM

Bookmarks

Bookmarks

     
        Algorithms and Data Structures

        Java tutorials

        Algorithms Forum

Posting Permissions

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