|
//字符串链表类
#ifndef CStrList_H
#define CStrList_H
#include "base.h"
//#include "intlist.h"
//#include "cstring.h"
class CStrList
{
protected:
CStrList *head;
CStrList *tail;
CStrList *next;
CStrList *freepoint; //游标指针
CString m_num; //成员的值
int m_count;//成员数量
public:
CStrList operator +(CStrList &_obj);
void operator =(CStrList &_obj);
void operator =(CString &_str);
CStrList operator +(char *_value);
bool operator ==(CStrList &_obj);
CStrList ()
{
head = tail = next = freepoint = NULL;
//m_num = NULL;
m_count = 0;
}
CStrList (CString &_str)
{
head = tail = next = freepoint = NULL;
m_count = 0;
Append (_str);
}
CStrList (char* _value)
{
head = tail = next = freepoint = NULL;
m_count = 0;
Append (_value);
}
~CStrList ()
{
Close();
}
/*
CStrList (CStrList& _CStrList)
{
head = tail = next = freepoint = NULL;
m_count = 0;
for (int i = 1;i <= _CStrList.Count();i++)
{
Append(_CStrList.Get(i));
}
}
*/
/*########################*/
//void CStrList:: Insert (CString &_obj,int _pos)
//插入链表中的指定位置
/*########################*/
void CStrList:: Insert (CString &_obj,int _pos)
{
if (_pos < 1)
{
PRINT("Insert--parameter pos error!")
return;
}
//插入的位置大于现有成员数量
if (_pos > Count())
{
Append(_obj);
return;
}
//插入到第1个位置
else if (_pos == 1)
{
CStrList *item;
NEW(item,CStrList);
//item->m_num = new(char);
item->m_num = _obj;
item->next = head;
head = item;
m_count++;//成员数加1
return;
}
//插入到中间位置
else
{
CStrList *tmp;
tmp = head;
int t_pos = 1;
while (tmp != NULL)
{
if ((t_pos + 1) == _pos)
{
CStrList *item;
NEW(item,CStrList);
item->m_num = _obj;
CStrList &front = *tmp;//指向要插入位置的前一个成员
tmp = tmp->next;//指向要插入的位置;
front.next = item;
item->next = tmp;
m_count++;//成员数加1
return;
}
tmp=tmp->next;
t_pos++;
}
}
}
/*########################*/
//void CStrList:: Insert (CStrList &_obj,int _pos)
//插入链表中的指定位置
/*########################*/
void CStrList:: Insert (CStrList &_obj,int _pos)
{
if (_pos < 1)
{
PRINT("Insert---parameter pos error!")
return;
}
CStrList* tmp;
tmp = _obj.head;
int i = 0;
while (tmp != NULL)
{
Insert(_obj.Get(i+1),_pos + i);
i++;
tmp = tmp->next;
}
return;
}
/*########################*/
//void CStrList:: Insert (char *_value,int _pos)
//插入链表中的指定位置
/*########################*/
void CStrList:: Insert (char *_value,int _pos)
{
CString obj;
obj = _value;
Insert(obj,_pos);
return;
}
/*########################*/
//void Close ()
//修改成员的值
/*########################*/
void Close ()
{
//CStrList* tmp;
for (int i = 1;i <= m_count;i++)
{
//tmp = head;
//head = head->next;
//DELETE(tmp);
Retrieve();
}
head = tail = next = freepoint = NULL;
m_count = 0;
return;
}
[ 本帖最后由 wwtsanmao 于 2009-12-18 17:03 编辑 ] |
|