#ifndef LINKQUEUE_H
#define LINKQUEUE_H
#include "Queue.h"
#include "linklist.h"
#include "Exception.h"
namespace DragonLib {
template <typename T,int N>
class StaticQueue : public Queue
{
protected:
LinkList<T> m_list;
public:
LinkQueue()
{
}
void add(const T&e)
{
m_list.insert(e);
}
void remove()
{
if(m_list.length()>0)
{
m_list.remove(0);
}
else
{
THROW_EXCEPTION(InvalidOperationException,"No element in current queue...");
}
}
T front() const
{
if(m_list,length()>0)
{
return m_list.get(0);
}
else
{
THROW_EXCEPTION(InvalidOperationException,"No element in current queue...");
}
}
void clear()
{
m_list.clear();
}
int length() const
{
return m_list.length();
}
};
}
#endif // LINKQUEUE_H
优化:
第25行会调用10次构造函数,顺序队列和顺序栈都有这样的相同问题,效率不高