#pragma once
#include<assert.h>
template <class _Ty>
class list
{
public:
struct _Node;
typedef _Node* _Nodeptr;
struct _Node {
_Ty value;
_Nodeptr prev;
_Nodeptr next;
};
typedef _Ty value_type;
typedef _Ty* pointer_type;
typedef _Ty& reference_type;
typedef const _Ty& const_reference_type;
typedef const _Ty* const_pointer_type;
typedef int difference_type;
private:
_Nodeptr _head;
size_t _size;
public:
explicit list():_head(_Buynode()),_size(0) {
}
void push_back(const _Ty value) {
_Nodeptr _s = _Buynode(_head,_head->prev);
_s->value = value;
_head->prev->next = _s;
_head->prev = _s;
_size++;
}
void push_front(const _Ty value) {
}
void pop_back() {
}
protected:
_Nodeptr _Buynode(_Nodeptr _Narg=0,_Nodeptr _Parg=0) {
_Nodeptr _s = (_Nodeptr)malloc(sizeof(_Node));
assert(_s != NULL);
_s->next = _Narg!=0?_Narg:_s;
_s->prev = _Parg!=0?_Parg:_s;
return _s;
}
};
这是一个C++模板类List的实现,包含节点结构定义、数据类型别名以及基本操作如push_back、push_front。类中定义了双向链表的节点,并提供了插入元素到链表尾部的功能,但push_front和pop_back方法尚未实现。
2831

被折叠的 条评论
为什么被折叠?



