wwtsanmao 发表于 2009-12-14 17:56:11

cstrlist.2h

/*########################*/
//void Set (CString &value,int pos)
//修改成员的值
/*########################*/
void Set (CString &value,int pos)
{
CStrList* tmp;
tmp = head;
int i = 1;
while (tmp != NULL)
{
   if(pos == i)
   {
    tmp->m_num = value;
    return;
   }
   tmp = tmp->next;
   i++;
}
PRINT("Set--member is not exist!");
return;
}
/*########################*/
//void Set (char *value,int pos)
//修改成员的值
/*########################*/
void Set (char *value,int pos)
{
CStrList* tmp;
CString obj;
obj = value;
tmp = head;
int i = 1;
while (tmp != NULL)
{
   if(pos == i)
   {
    tmp->m_num = obj;
    return;
   }
   tmp = tmp->next;
   i++;
}
PRINT("Set--member is not exist!");
return;
}
/*########################*/
//void Append (CString &_value)
//按顺序加入链表
/*########################*/
void Append (CString &_value)
{
Append(_value.Data());
return;
}
/*########################*/
//void Append (CStrList &_value)
//按顺序加入链表
/*########################*/
void Append (CStrList &_obj)
{
CStrList* tmp;
tmp = _obj.head;
int i = 1;
while (tmp != NULL)
{
   Append(_obj.Get(i));
   tmp = tmp->next;
   i++;
}
return;
}
/*########################*/
//void Append (const char* _value)
//按顺序加入链表
/*########################*/
void Append (const char* _value)
{
CStrList *item;
NEW(item,CStrList);
//new(_length);
item->m_num = _value;
if (tail != NULL)
{
   tail->next = item;
}
item->head = tail;
tail = item;
item->next = NULL;
if (head == NULL)
{
   head = tail;
}
m_count++;//成员数加1
return;
}
/*########################*/
//int Find (CString &_str)
//在链子表中查找,找到返回下标,否则返回-1
/*########################*/
int Find (CString &_str)
{
CStrList* tmp;
tmp = head;
int pos = 1;
while (tmp != NULL)
{
   if(_str == tmp->m_num)
   {
    return pos;
   }
   tmp = tmp->next;
   pos++;
}
return -1;
}
/*########################*/
//int Find (const char *_value)
//在链子表中查找,找到返回下标,否则返回-1
/*########################*/
int Find (const char *_value)
{
CString obj;
obj = _value;
return Find(obj);
}
/*########################*/
//CString Retrieve ()
//从前往后出链表
/*########################*/
//CString Retrieve ()
void Retrieve ()
{
CString tmp;
if (head != NULL && m_num.Data() != NULL)
{   
   CStrList* p;
   p = head;
   tmp = head->m_num;
   head = head->next;
   DELETE(p);
}
//else
//{
   //PRINT("Retrieve--CStrList is empty!");
//}
//return tmp;
return;
}
/*########################*/
//CString Get (int _pos)
//取得链表中指定成员,下标从1开始
/*########################*/
CString Get (int _pos)
{
CStrList* tmp;
tmp = head;
int t_pos = 1;
while (tmp != NULL)
{
   if (_pos == t_pos)
   {
    return tmp->m_num;
   }
   t_pos++;
   tmp = tmp->next;
}
PRINT("Get--member is not exist!");
//return NULL;
//CString err;
return m_num;
}

[ 本帖最后由 wwtsanmao 于 2009-12-18 17:03 编辑 ]
页: [1]
查看完整版本: cstrlist.2h