Click here to Skip to main content
15,890,438 members
Please Sign up or sign in to vote.
1.22/5 (2 votes)
See more:
bank queue sistem has work FİFO first in first out wright?

but there is special customers they have not wait in the queue, they comes out but they goes first.


what is the algorithm this kind of queue sistem?

we will use only one queue there is no lots of queue.
Posted
Updated 5-Mar-17 19:57pm

You might be looking for a Priority Queue. See http://en.wikipedia.org/wiki/Priority_queue[^].
 
Share this answer
 
Comments
Manfred Rudolf Bihy 2-Jan-12 10:06am    
Good answer! 5+
Andreas Gieriet 2-Jan-12 10:36am    
Thanks :-)
Espen Harlinn 2-Jan-12 11:57am    
5'ed!
RaviRanjanKr 2-Jan-12 14:24pm    
My 5+
Sergey Alexandrovich Kryukov 22-Jan-12 13:10pm    
Right, good reference.
--SA
This is called a priority queue, items in the queue are processed by their priority number first then FIFO order.
 
Share this answer
 
Comments
Manfred Rudolf Bihy 2-Jan-12 10:06am    
Correct answer! 5+
Mehdi Gholam 2-Jan-12 10:22am    
Thanks man.
Espen Harlinn 2-Jan-12 11:57am    
5'ed!
Mehdi Gholam 2-Jan-12 12:08pm    
Thanks Espen, Happy new year!
Sergey Alexandrovich Kryukov 22-Jan-12 13:08pm    
Short but to the point, a 5.
--SA
While the answers Andreas & Mehdi are good, you may want to investigate MSMQ[^] or something similar too.

MSMQ allows you to set the priority of messages, and it allows you to safely persist the elements in the queue. This is often important when you are handling money. You really, really don't want to loose track of money - so each step of your processing pipeline should be both transacted and persisted.

Best regards
Espen Harlinn
 
Share this answer
 
Comments
Mehdi Gholam 2-Jan-12 12:09pm    
A Queue system is a good idea too, although I find MSMQ a deployment nightmare.

5'ed
Espen Harlinn 2-Jan-12 12:21pm    
If you are not working inside a domain, there are some limitations. Setting it up on 2008 r2 has become fairly straight forward. When I'm working outside a domain I tend to stick to private queues.
Mehdi Gholam 2-Jan-12 12:27pm    
Now you mention it, I remember having problems with it out side of domains, it gave me so much hassle that I abandoned it and switched to something I wrote myself (which I had total control over).
Espen Harlinn 2-Jan-12 12:32pm    
I know, I've read your articles - neat :)
I've been down that road too, but that was in C++ and nearly 10 years ago.
Wendelius 5-Jan-12 17:18pm    
Definitely a good option. A bit steep learning curve but really useful. +5
There is an implementation of priority queues algorithm in the STL: "priority_queue"
The header is "queue"

It includes a new method "front" to add priority items.

http://www.cplusplus.com/reference/stl/priority_queue/[^]

http://www.cplusplus.com/reference/stl/priority_queue/priority_queue/[^]
 
Share this answer
 
Comments
RaviRanjanKr 4-Jan-12 2:26am    
5+
JackDingler 4-Jan-12 12:06pm    
That's an interesting addition, considering that std::deque can already do this.
Hi,

This is exactly priority queue. Each items in the queue are assigned a particular priority based on some criteria.The processing is carried out based on this criteria. The item with most priority is processed first and so on.


Cheers
 
Share this answer
 
Comments
fjdiewornncalwe 4-Jan-12 11:43am    
Please don't post answers that are duplicates of others. Upvote those answers instead.
All these answers are good. Better you can use a priority queue or you can use a linked list to act as a queue. The linked list must contain a structure with an item to denote whether the particular item has a priority or not.

So each time when you take the data from linked list, traverse the entire list to check whether any priority item is present or not.

If present, take that item.

Else take the first item in list which will be first item you have entered. So it will work on a FIFO basis with priority scheduling.
 
Share this answer
 
Comments
fjdiewornncalwe 4-Jan-12 11:43am    
Please don't post answers that are duplicates of others. Upvote those answers instead.
All of my colleagues are correct as far as computer science is concerned. Priority queues allow you to enter elements in the proper order for removal. Multi-queue / multi-server queues allow for a totally different priority track for inportant transactions / elements.

Priority Queues work well in computer applications but fail horribly when applied to real people. Have you ever tried to user your "priority customer card" at a bank, or worse yet, in the ticket line at a concert. It's called "line jumping" and you will incur the wrath of everybody else in line. You will be forced to explain your "priority" to everybody else in line and they are the ones who decide if your "priority" is valid or if you are kicked out of line.

Multi-Queue (whether single or multi-server) work best in "people" applications. Consider the Ticket Office at the MGM Grand at Foxwoods where there is the "general ticket pick-up" line snaking through the lobby and the "Platinum and Diamond Elite" line which is very short and has it's own ticket agent. Nobody argues with you when you get into that line, the ticket agent checks your status at the desk and politely asks you to go to the other line if you are in the wrong line. Everything flows smoothly and pleasantly.

So, if you are working with cold, emotionless applications that do not care if another applications / task / transaction / thread jumps in front of them, Priority queues are the way to go. If you are working with people, separate the elite from the great unwashed public whenever you can (multi-queue).

Just my 2 cents worth :)
 
Share this answer
 
Comments
Andreas Gieriet 2-Jan-12 13:02pm    
Hello Chuck,

leaving the emotions of people's world queuing away ;-) , I consider multi-queuing an implementation detail of the priority-queue concept.

On the other hand, I also experienced in "real life", that a single-queue priority-queue worked well: "higher priority" individuals were picked out of the queue by a "dispatcher" - it basically depends on the acceptance level of the priorities for the individuals or the authority doing the dispatching (e.g. see emergency room triage).

Cheers

Andi
Member-2338430 3-Jan-12 7:38am    
is there code this about algorithm with c++?
Andreas Gieriet 4-Jan-12 5:53am    
How about google...? "c++" priority queue

E.g. priority queue
Great answers above...

If I were writing this queue it might look something like this...

C++
#pragma once

#include <map>
#include <deque>

template<class T>
class CPriorityQueueT
{
protected:
    std::map<int, std::deque<T>>	PriorityMap;

public:
    bool	PushMessage(const T & Message, int Priority = 5);

public:
    bool	PopMessage(T & Message, int * pPriority = NULL);
};

template<class T>
bool CPriorityQueueT<T>::PushMessage(const T & Message, int Priority)
{
    // Find the deqeue that has the same priority
    std::map<int, std::deque<T>>::iterator Iter = PriorityMap.find(Priority);
    if (Iter == PriorityMap.end())
    {
        // The deque doesn't exist. Create it.
        PriorityMap.insert(std::pair<int, std::deque<T>>(Priority, std::deque<T>()));
        Iter = PriorityMap.find(Priority);
    }
    
    // Add the message to the deque
    std::deque<T> & Deque = (*Iter).second;
    Deque.push_back(Message);
    
    return true;
}

template<class T>
bool CPriorityQueueT<T>::PopMessage(T & Message, int * pPriority)
{
    std::map<int, std::deque<T>>::iterator Iter = PriorityMap.begin();
    std::map<int, std::deque<T>>::iterator End  = PriorityMap.end();
    
    // Loop through the map and see if any of the priority deques have data.
    for (; Iter != End; Iter++)
    {
        if ((*Iter).second.size())
            break;
    }
    
    if (Iter == PriorityMap.end())
    {
        // All deques are empty. Exit.
            return false;
    }

    if (pPriority)
        *pPriority = (*Iter).first;
    
    std::deque<T> & Deque = (*Iter).second;
    Message = Deque.front();
    Deque.pop_front();
    
    return true;
}
 
Share this answer
 
v11
Comments
JackDingler 4-Jan-12 11:47am    
sorry about the lack of indents, I couldn't get this system to show the LTs, GTs and indents all at the same time.

This editing system still has some bugs to work out.
JackDingler 4-Jan-12 14:26pm    
thanks for the cleanup. :)
JackDingler 4-Jan-12 15:58pm    
BTW, if this is for a homework assignment, make sure you can explain how it works. :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900