|
/*########################*/
//int Next ()
//取得链表中的下一个成员
/*########################*/
int Next ()
{
if (freepoint)
{
list* tmp;
tmp = freepoint;
freepoint = freepoint->next;
PRINT(tmp->m_num);
return tmp->m_num;
}
else
{
PRINT("this is the tail!");
return NULL;
}
}
/*########################*/
//void Show ()
//打印链表所有成员
/*########################*/
void Show ()
{
list* tmp;
tmp = head;
int i = 0;
while (tmp)
{
PRINT(tmp->m_num);
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("member is not exist!");
return;
}
else
{
list *tmp;
tmp = head;
int t_pos = 1;
while (tmp)
{
//删除第一个
if (pos == 1)
{
head = head->next;
delete tmp;
m_count--;//成员数量减1
return;
}
//删除的不是第一个
if ((t_pos + 1) == pos)
{
list &front = *tmp;//指向要删除位置的前一个成员
list *back;
tmp=tmp->next;//指向要删除的位置
back=tmp->next;//指向要删除位置的后一个成员
front.next = back;//将要删除位置的前一个成员指向要删除位置的后一个成员
delete tmp;
m_count--;//成员数量减1
return;
}
t_pos++;
tmp = tmp->next;
}
}
}
/*########################*/
//void Sort ()
//降序排列
/*########################*/
void Sort ()
{
InsideSort (0);
}
/*########################*/
//void VSort ()
//升序排列
/*########################*/
void VSort ()
{
InsideSort (1);
}
void test ()
{
list* tmp;
tmp = head;
PRINT("*********************");
PRINT("tmp->next->m_num=");
PRINT(tmp->next->m_num);
return;
}
private:
/*########################*/
//void InsideSort (Int2 flag = 0)
//0:降序排列,1:升序排列
/*########################*/
void InsideSort (Int2 flag = 0)
{
if (head)
{
list *tmp1,*tmp2;
tmp1 = head;
tmp2 = tmp1->next;
int t_value = 0;
while (tmp1)
{
while (tmp2)
{
//降序排列
if (flag == 0)
{
if (tmp1->m_num > tmp2->m_num)
{
t_value = tmp2->m_num;
tmp2->m_num = tmp1->m_num;
tmp1->m_num = t_value;
}
}
//升序排列
else
{
if (tmp1->m_num < tmp2->m_num)
{
t_value = tmp2->m_num;
tmp2->m_num = tmp1->m_num;
tmp1->m_num = t_value;
}
}
tmp2 = tmp2->next;
}
tmp1 = tmp1->next;
if (tmp1)
{
tmp2 = tmp1->next;
}
}
}
}
};
#endif |
|