list.h
来自「3D游戏开发需要用到BSP树来经行场景渲染的管理。本代码包含完整的BSP及文件生」· C头文件 代码 · 共 73 行
H
73 行
#pragma once
template <class type>
class CList {
public:
struct node {
node(type& d, node *n): data(d), next(n) {};
type data;
node *next;
};
CList();
~CList();
void PushFront(type t);
type* PopFront();
type* PeekFront();
void Clear();
void ClearData();
private:
node *head;
};
template <class type>
inline CList<type>::CList(): head(0) {};
template <class type>
inline CList<type>::~CList() {
Clear();
}
template <class type>
inline void CList<type>::PushFront(type t) {
node *n = new node(t, head);
head = n;
}
template <class type>
inline type* CList<type>::PeekFront() {
return head->data;
}
template <class type>
inline type* CList<type>::PopFront() {
type *r = head->data;
node *popped = head;
head = head->next;
delete popped;
return r;
}
template <class type>
inline void CList<type>::Clear() {
node *n = head;
while(n) {
node *cur = n;
n = n->next;
delete cur;
}
head = 0;
}
template <class type>
inline void CList<type>::ClearData() {
node *n = head;
while(n) {
node *cur = n;
n = n->next;
delete cur->data;
delete cur;
}
head = 0;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?