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

cstrlist3.h

/*########################*/
//CString First ()
//取得链表第一个成员
/*########################*/
CString First ()
{
if (head != NULL)
{
   freepoint = head->next;
   return head->m_num;
}
PRINT("First--member is not exist!");
//return NULL;
//CString err;
return m_num;
}
/*########################*/
//CString Next ()
//取得链表中的下一个成员
/*########################*/
CString Next ()
{
if (freepoint != NULL)
{
   CStrList* tmp;
   tmp = freepoint;
   freepoint = freepoint->next;
   //PRINT(Next--tmp->m_num);
   return tmp->m_num;
}
else
{
   PRINT("Next--this is the tail!");
   //return NULL;
   //CString err;
   //return err;
   return m_num;
}
}
/*########################*/
//void Show ()
//打印链表所有成员
/*########################*/
void Show ()
{
CStrList* tmp;
tmp = head;
int i = 0;
while (tmp != NULL)
{
   PRINT(tmp->m_num.Data());
   tmp = tmp->next;
   i++;
}
m_count = i;//修正成员数量
}
/*########################*/
//int Count ()
//返回链表中的成员个数
/*########################*/
int Count ()
{
return m_count;
}
/*########################*/
//void Remove (int pos)
//删除指定成员,下标从1开始
/*########################*/
void Remove (int pos)
{
if (pos > Count())
{
   PRINT("Remove--member is not exist!");
   return;
}
else
{
   CStrList *tmp;
   tmp = head;
   int t_pos = 1;
   while (tmp != NULL)
   {
    //删除第一个
    if (pos == 1)
    {
   head = head->next;
   DELETE(tmp);
   m_count--;//成员数量减1
   return;
    }
    //删除的不是第一个
    if ((t_pos + 1) == pos)
    {
   CStrList&front = *tmp;//指向要删除位置的前一个成员   
   CStrList *back;
   tmp=tmp->next;//指向要删除的位置
   back=tmp->next;//指向要删除位置的后一个成员
   front.next = back;//将要删除位置的前一个成员指向要删除位置的后一个成员
   DELETE(tmp);
   m_count--;//成员数量减1
   return;
    }
    t_pos++;
    tmp = tmp->next;
   }
}
}
};

/*########################*/
//CStrList CStrList:: operator +(CStrList &_obj)
//重载加法操作
/*########################*/
CStrList CStrList:: operator +(CStrList &_obj)
{
CStrList resault;

/*for (int i = 1;i <= Count();i++)
{
resault.Append(Get(i));
}
for (i = 1;i <= _obj.Count();i++)
{
resault.Append(_obj.Get(i));
}*/
resault.Append(*this);
resault.Append(_obj);
return resault;
}
/*########################*/
//CStrList CStrList:: operator +(char *_value)
//重载加法操作
/*########################*/
CStrList CStrList:: operator +(char *_value)
{
CStrList resault;
resault.Append(*this);
resault.Append(_value);
return resault;
}
/*########################*/
//void CStrList:: operator =(CStrList &_obj)
//重载赋值操作
/*########################*/
void CStrList:: operator =(CStrList &_obj)
{
Close();
Append(_obj);
return;
}
/*########################*/
//void CStrList:: operator =(CString &_obj)
//重载赋值操作
/*########################*/
void CStrList:: operator =(CString &_str)
{
Close();
Append(_str);
return;
}
/*########################*/
//bool CStrList:: operator ==(CStrList &_obj)
//
/*########################*/
bool CStrList:: operator ==(CStrList &_obj)
{
if (this->Count() != _obj.Count())
{
return false;
}
for (int i = 1;i <= this->Count();i++)
{
//if (this->Get(i) != a.Get(i))
if (!(this->Get(i) == _obj.Get(i)))
{
   return false;
}
}
return true;
}
#endif

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