|
此文章由 内核 原创或转贴,不代表本站立场和观点,版权归 oursteps.com.au 和作者 内核 所有!转贴必须注明作者、出处和本声明,并保持内容完整
碰到4个中介都用同一套题来考偶~~拿出来给大家参考参考~~
You are required to implement a queue, as illustrated by the following diagram:
The queue must have the following features:
• Thread safe for any number of reading and writing threads
• The Dequeue method must be blocking. i.e. it does not return until it can retrieve an item from the queue.
You may choose to implement the queue in either C++ or C#. Please select from the prototypes listed below.
You are only required to implement the Enqueue and Dequeue methods.
If you are unsure of the syntax of any commands you are using please make sure the intent of your code is clear via inline comments or similar.
C# Prototype using .NET Generics
class WaitableQueue<T>
{
private Queue<T> _queue;
public WaitableQueue();
public void Enqueue(T item);
public T Dequeue();
}
C++ Prototype using templates and the STL
template <class T>
class WaitableQueue
{
public:
WaitableQueue();
virtual ~WaitableQueue();
void Enqueue(T* item);
T* Dequeue();
private:
std::queue<T> _queue;
}; |
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有帐号?注册
x
评分
-
查看全部评分
|