Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1193
  • Last Modified:

C# console application

what is linear queue and circular queue.how can i define?
0
beeravally
Asked:
beeravally
1 Solution
 
MudieCommented:
A linear queue is merely a normal queue.
Queue myQueue = new Queue();

You can add items to the queue.
myQueue.Enqueue("a");
myQueue.Enqueue("b");

And you can remove items from the queue.
myQueue.Dequeue();

When you add an item to the queue it goes to the end of the line. Removing items from the queue removes the item at the start of the line.
Just like a bank window, it's first in first out FIFO. Thus now the queue contains only b as the dequeue command removed a. This is demonstrated in the following sample code:

            private void button1_Click(object sender, System.EventArgs e)
            {
                  //instantiate myQueue
                  Queue myQueue = new Queue();

                  //add a and b to myQueue
                  myQueue.Enqueue("a");
                  myQueue.Enqueue("b");

                  //dequeue an item from myQueue, in this case item a
                  myQueue.Dequeue();

                  //show the first item in the queue
                  MessageBox.Show( Convert.ToString(myQueue.Peek()) );
            }

Create a button and double click it, copy and past the above code over the buttons Click event.

For more information see MSDN: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemCollectionsQueueClassTopic.asp


There isn't a nice class to use for circular queues, you can make one via an array however. The following webpage talks about circular queues: http://people.cs.uct.ac.za/~bmerry/manual/structures/circular.html

In a nutshell it's an optimized type of queue as insertation and deletion are independent. It has a "head" and a "tale" and if the tale is before the head it wraps around, hence the name circular queue. The array being used as the circular queue has one more item then is needed inorder to differentiate between being full or empty. Insertation is done by inserting to the tail index then incrementing the tail and finally wrapping if needed. Deleting is done by deleting the element at the head index and then incrimenting the head.

C implimentation & delete algorithm: http://datastructures.itgo.com/staque/queues/circular/delete.htm
C implimentation & insert algorithm:
http://datastructures.itgo.com/staque/queues/circular/insert.htm

If you need more information let me know.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now