-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathslist.h
67 lines (58 loc) · 1.56 KB
/
slist.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/*
* =====================================================================================
*
* Filename: slist.h
*
* Description: 单链表
*
* Version: 1.0
* Created: 2015年03月19日 19时37分51秒
* Revision: none
* Compiler: gcc
*
* Author: sherlock-coding
* Organization: njust
*
* =====================================================================================
*/
#ifndef _SINGLE_LIST_H_
#define _SINGLE_LIST_H_
template <typename T>
class Node {
public:
Node():data(T()), next(nullptr){}
Node(const T &initdata):data(initdata), next(nullptr) {}
Node(const T &initdata, Node<T> *pNode):data(initdata), next(nullptr) {}
~Node() {}
T data;
Node<T> *next;
};
template <typename T>
class SList {
public:
SList();
SList(const T& initdata);
~SList();
int IsEmpty();
int GetCount() const;
T& GetTail();
const T& GetTail() const;
T& GetHead();
const T& GetHead() const;
T& GetAt(const int pos);
const T& GetAt(const int pos) const;
void SetAt(const int pos, const T& data);
int Find(const T& data);
int AddHead(const T& data);
int AddTail(const T& data);
int InsertBefore(const T& data, const int pos);
int InsertAfter(const T& data, const int pos);
void RemoveAt(const int pos, T& ret);
void RemoveHead(T& ret);
void RemoveTail(T& ret);
void RemoveAll();
protected:
int m_nCount;
Node<T> *m_pNodeHead;
};
#endif