473,500 Members | 1,664 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

my priority queue

Hi all
I want to now your opinion on my priority queue. I know stl has one
very useful but I couldn't use stl. Code below shows the main part of
implementation :
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// 1) class interface like std::priority_queue
template<
class _Ty,
class _Predicate = Less<_Ty>,
class _Container = Array<_Ty>
>
class StlPriorityQueuePolicy
{
_Container m_container;
public:
// common interface
_Ty& top();
void pop();
push(const _Ty& val);
};
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// 2) class interface only pop and push
emplate<
class _Ty,
class _Predicate = Less<_Ty>,
class _Container = Array<_Ty>
>
class PushpopPriorityQueuePolicy : protected
StlPriorityQueuePolicy<_Ty, _Predicate, _Container >
{
typedef StlPriorityQueuePolicy<_Ty, _Predicate, _Container >
base;
public:
// common interface
_Ty pop(){
if(base::is_empty()) throw exception;
_Ty val = base::top();
base::pop();
return val;
};
push(const _Ty& val){
base::push(val);
}
};

emplate<
class _Ty,
class _Predicate = Less<_Ty>,
class _Container = Array<_Ty>,
class _Policy = StlPriorityQueuePolicy<_Ty, _Predicate, _Container
>
class PriorityQueuePolicy : public _Policy<_Ty, _Predicate,
_Container{};
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Maybe it is too compliceted. I like the second policy
(PushpopPriorityQueuePolicy) but it has one disadvantage. Pop method
has to create new value before the value is poped from priority queue
and returned.

Can you tell me your opinion.
Thanks
Oct 25 '08 #1
0 1048

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

38
5730
by: Aaron W. LaFramboise | last post by:
Hello, I understand that an easy way to make the standard std::priority_queue stable is by including an integer stamp with each node that is incremented each time a new node is pushed into the...
5
13200
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...
3
1360
by: Erik | last post by:
Hi Everyone, I was thinking of how to do this for a while now and I cant get my head round it so I though I'd ask the experts! :-) What I am doing is reading in large amounts of data over TCP...
16
5369
by: Crirus | last post by:
hello I read somewhere about priority queue...what is that and Vb net have such class? -- Ceers, Crirus ------------------------------ If work were a good thing, the boss would take it...
4
10342
by: vfunc | last post by:
Is the STL priority queue a proper implementation of a heap with siftup algorithm etc ? How do you implement an STL priority queue (link to an example) ? Is there a resort method, why ? Thanks
3
4345
by: Chris Lasher | last post by:
Hello, I am working with large graphs (~150,000 to 500,000 nodes) which I need decompose node-by-node, in order of a node's value. A node's value is determined by the sum of its edge weights....
3
7396
by: PicO | last post by:
i need some explanation about the difference between priority queue & set & heap ... as they all sort the data in ( n log n ) ... but the only i see that priority queue only can pop the top (...
1
3948
by: operatingsystem | last post by:
I need to generate such scheduler in operating system subject which satisfy below conditions...may i request u if anybody knows abt this plz help me out in this..topics.. Scheduler...
4
3405
by: jjh5030 | last post by:
This is a programming assignment. You are asked to work with pointers. Be aware that error messages are often not very helpful when your pointers point to bad locations. Therefore, reserve...
14
16920
by: AlarV | last post by:
Hello everyone, here is my problem. I have to make a dynamic priority queue,which is a heap, and my book isn't helpful at all, so I have no clues on how to create it.. I read something like a static...
0
7136
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,...
0
7018
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...
0
7183
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,...
1
6909
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7397
tracyyun
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...
0
5491
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,...
1
4923
isladogs
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...
0
3110
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...
0
3108
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.