Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get the index of an element inside queue c#

I have a queue of users(string of emails) a in c# and I want to send the user his location in this queue.

something like ;

Queue q = new Queue(32);

q.Enqueue(Session["email"].ToString());

    queue.IndexOf(email);

Any ideas?

thanks

like image 720
baaroz Avatar asked Mar 25 '12 18:03

baaroz


People also ask

Can you index into a queue?

In an Indexed Priority Queue, data is stored just like standard priority queue and along with this, the value of a data can be updated using its key. It is called “indexed” because a hash map can be used to store the index in container using the key of key-value pair input as the key of hash map.

How do I find the queue element?

It is used when you need a first-in, first-out access of items. When you add an item in the list, it is called enqueue, and when you remove an item, it is called deque. Queue . Contains(T) Method is used to check whether an element is in the Queue .

How do you know how many elements are in a queue?

Count Property is used to get the number of elements contained in the Queue. Properties: Enqueue adds an element to the end of the Queue. Dequeue removes the oldest element from the start of the Queue.

How do you access queue elements in Python?

To obtain the first element and the last element in the queue, the most straightforward way is to use indices. The first element in the queue has an index of 0. For the last item in the queue, we can use the -1 index. The minus sign indicates to Python to start counting items backward from the end of the queue.


1 Answers

Maybe a List or an Array would be better for such actions but you could try this:

queue.ToArray().ToList().IndexOf(email);
like image 95
ionden Avatar answered Sep 20 '22 21:09

ionden