📄 stringlist.h
字号:
// StringList.h: interface for the CStringList class.
//
//////////////////////////////////////////////////////////////////////
#ifndef _STRINGLIST_H_
#define _STRINGLIST_H_
#ifndef POSITION
typedef struct{} *POSITION;
#endif
class CStringList
{
protected:
struct CNode
{
CNode* pNext;
CNode* pPrev;
CString data;
};
public:
// Construction
CStringList();
// Attributes (head and tail)
// count of elements
int GetCount() const;
BOOL IsEmpty() const;
// peek at head or tail
CString& GetHead();
CString GetHead() const;
CString& GetTail();
CString GetTail() const;
// Operations
// get head or tail (and remove it) - don't call on empty list!
CString RemoveHead();
CString RemoveTail();
// add before head or after tail
POSITION AddHead(LPCTSTR newElement);
POSITION AddTail(LPCTSTR newElement);
POSITION AddHead(const CString& newElement);
POSITION AddTail(const CString& newElement);
// add another list of elements before head or after tail
void AddHead(CStringList* pNewList);
void AddTail(CStringList* pNewList);
// remove all elements
void RemoveAll();
// iteration
POSITION GetHeadPosition() const;
POSITION GetTailPosition() const;
CString& GetNext(POSITION& rPosition); // return *Position++
CString GetNext(POSITION& rPosition) const; // return *Position++
CString& GetPrev(POSITION& rPosition); // return *Position--
CString GetPrev(POSITION& rPosition) const; // return *Position--
// getting/modifying an element at a given position
CString& GetAt(POSITION position);
CString GetAt(POSITION position) const;
void SetAt(POSITION pos, LPCTSTR newElement);
void SetAt(POSITION pos, const CString& newElement);
void RemoveAt(POSITION position);
// inserting before or after a given position
POSITION InsertBefore(POSITION position, LPCTSTR newElement);
POSITION InsertAfter(POSITION position, LPCTSTR newElement);
POSITION InsertBefore(POSITION position, const CString& newElement);
POSITION InsertAfter(POSITION position, const CString& newElement);
// helper functions (note: O(n) speed)
POSITION Find(LPCTSTR searchValue, POSITION startAfter = NULL) const;
// defaults to starting at the HEAD
// return NULL if not found
POSITION FindIndex(int nIndex) const;
// get the 'nIndex'th element (may return NULL)
// Implementation
protected:
CNode* m_pNodeHead;
CNode* m_pNodeTail;
int m_nCount;
void FreeNode(CNode*);
public:
~CStringList();
};
#endif //_STRINGLIST_H_
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -