//模板递归推导数列
template<int ...args>
struct idx_holder {
};
template<int N, class Holder>
struct idx_seq {
typedef idx_seq<N, Holder> seq;
};
template<int N, int...Ns>
struct idx_seq<N, idx_holder<Ns...>> {
typedef typename idx_seq<N - 1, idx_holder<N, Ns...>>::seq seq;
};
template<int... Ns>
struct idx_seq<1, idx_holder<Ns...>> {
typedef idx_holder<1, Ns...> seq;
};
template<int N>
constexpr typename idx_seq<N, idx_holder<>>::seq make_idx_seq()
{
return {};
}
void pf(int a, int b, int c)
{
std::cout << a << b << c << std::endl;
}
template<int... idSqs>
void use_seq(idx_holder<idSqs...>)
{
pf(idSqs...);
}
template<class T>
struct DbNode {
T data;
DbNode<T> *pred, *next;
DbNode(const T &value, DbNode<T> *a = nullptr, DbNode<T> *b = nullptr) :\
data(value), pred(a), next(b) {}
DbNode(DbNode<T> *a = nullptr, DbNode<T> *b = nullptr) :pred(a), next(b) {}
};
template <typename T>
class CircDbList {
public:
CircDbList() :m_pHead(nullptr) {};
~CircDbList() { Release(); };
void Release();
DbNode<T> *CreateHead(const T& data);
DbNode<T> *Add(DbNode<T> *node, BOOL bIsEnd = TRUE);
DbNode<T> *Add(const T& data, BOOL bInEnd = TRUE);
BOOL Remove(DbNode<T> *node, BOOL bIsDel = TRUE);
BOOL PopNode(DbNode<T> *node);
void Print(int n);
private:
DbNode<T> *m_pHead;
};
template <typename T>
void CircDbList<T>::Print(int n) {
if (n) //正序打印
{
std::cout << "Positive order: ";
DbNode<T> *tmp = m_pHead;
while (tmp->next != m_pHead) {
std::cout << tmp->data << "->";
tmp = tmp->ne
C++ 循环链表
最新推荐文章于 2024-04-21 17:11:32 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)