473,890 Members | 1,342 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Queue using array

60 New Member
Hi
i've implemented a linear Queue using array.
But i've been struck up with a doubt!!!!!

Let me tell my problem with an example so that it can be clear.

Size of the Queue(array) is 5.
im initializing the front and rear to 0.
I continously add five elements to the Queue, so that now the rear points to the 4th position of the array and now the queue is full.
Now i delete all the five elements and now the Front and the Rear points at the 4th position of the array.
My problem starts here.
Now the Queue is empty. Whether i've to reset the position of rear and front to 0 or not?
Mar 14 '07 #1
2 2582
DeMan
1,806 Top Contributor
If the Queue is empty, then it probably doesn't matter which element you are pointing at, as long as the algorithm is well implemented.
As a point of functionality, however, I think that the pointer should point to the first (0th) element of the array, as a delete operations should probably move to the next element....
That is, if you have three elements and delete 2, you would want to point to the remaining (third) element. Likewise if you have 5 elements and delete all 5, you want to point to the NEXT (6th) element, which in this case would be the first...
Mar 14 '07 #2
palani12kumar
60 New Member
ok.
thank you for your help.
Mar 17 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

7
4442
by: Shailesh Humbad | last post by:
I wrote a simple, but proprietary queue class that efficiently enqueues and dequeues arbitrary length byte arrays. I would like to replace it with an STL container if the performance overhead is not too high. Currently, I am thinking of replacing it like shown below, but it is not efficient due to repeated function calls to "push". Can anyone with more STL experience show a better way to use it, if there is one? // CUSTOM QUEUE //...
5
13257
by: Dan H. | last post by:
Hello, I have implemented a C# priority queue using an ArrayList. The objects being inserted into the priority queue are being sorted by 2 fields, Time (ulong) and Priority (0-100). When I enqueue, I do a binary search on where to put the object and then insert using that index and arraylist.insert(index, obj) The bottom of my arraylist is always my lowest, therefore, dequeueing is very fast and effecient.
19
6262
by: ern | last post by:
I need a FIFO queue of size 20, to keep track of a running average. Once the queue is full with 20 values, I want to take the sum/20 = AVERAGE. Then when a new value comes in, I want: (Old Sum - oldest value + newest value)/20 = New Average Anybody know an efficient way to implement that? Is a queue even the best way? Thanks,
2
6590
by: pwalessi1 | last post by:
Hi. I have a Queue<T> that I need to serialize, but when I try, I get the error: "You must implement a default accessor on System.Collections.Generic.Queue" It is my understanding that the default accessor has the form, "function (int index)". But, that doesn't make any sense for a queue. The reason that I am using a queue is for FIFO access. Anyway, is there any way that I can serialize my queue?
8
14242
by: Jack | last post by:
I want to implement a fixed-size FIFO queue for characters. I only want to use array not linked list. For example, const int N = 10; char c_array; The question is when the queue is full, there are ten characters in the
7
2585
by: Michael D. Ober | last post by:
When calling Enqueue, the internal array may need to be reallocated. My question is by how much? In the old MFC array classes, you could tell MFC how many additional elements to add to the array when it needed to reallocate, which greatly boosted performance relative to adding 1 element at a time. Thanks, Mike Ober.
4
4606
by: j_depp_99 | last post by:
Thanks to those guys who helped me out yesterday. I have one more problem; my print function for the queue program doesnt work and goes into an endless loop. Also I am unable to calculate the length of my queue. I started getting compilation errors when I included a length function. <code> template<class ItemType> void Queue<ItemType>::MakeEmpty() {
0
1759
by: kmoeWW | last post by:
Hi all, I'm using the PICC CCS C compiler and am having issues with starting an enque/deque for my program. What I need it to do is to hold about 9 data packets, each packet is an array of 4 HEX integers. Each array is a different command for the program. example of array commands: int ph = {0x18, 0x2B, 0x00, 0x00}; int zt = {0x28, 0x35, 0x00, 0x00}; int zw = {0x28, 0x37, 0x00, 0x00}; int af = {0x28, 0x41, 0x00,...
3
2985
by: =?Utf-8?B?Y2hyaXNiZW4=?= | last post by:
Here are the codes Queue<string> q = new Queue<string>; Console.WriteLine(q.Count + ""); The program will crash since q is null. So my question is that what is the best way for new to initialize the array with generic queue as the value?
0
9978
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9819
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11222
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10811
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9625
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
7169
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5846
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4674
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4270
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.