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?
2 2573 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...
ok.
thank you for your help.
Sign in to post your reply or Sign up for a free account.
Similar topics |
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
//...
|
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.
|
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,
|
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?
|
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
| |
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.
|
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()
{
|
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,...
|
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?
|
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...
|
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...
| |
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...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
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();...
|
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
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |