newNode->next = m_pList->next;
m_pList->next = newNode;
插入节点的时候这个可以有,就是不太容易理解
m_pList->next = newNode;
插入节点的时候这个可以有,就是不太容易理解
2017-06-08
bool List::ListDelete(int i, Elem *e)
{
if (ListEmpty() || i >= m_iLength || i < 0)
{
return false;
}
*e = m_pList[i];
for (int k = i + 1; k < m_iLength; k++)
{
m_pList[k - 1] = m_pList[k];
}
m_iLength--;
return true;
}
这里的i指的是删除数组索引i上的元素
{
if (ListEmpty() || i >= m_iLength || i < 0)
{
return false;
}
*e = m_pList[i];
for (int k = i + 1; k < m_iLength; k++)
{
m_pList[k - 1] = m_pList[k];
}
m_iLength--;
return true;
}
这里的i指的是删除数组索引i上的元素
2017-06-07
bool List::ListInsert(int i, Elem *e) //i的意思并不是下标,而是第i个元素
{
if (i < 0 || i > m_iLength || m_iLength == m_iSize || ((i != 0) && ListEmpty()))
{
return false;
}
for (int k = m_iLength - 1; k >= i; k--)
{
m_pList[k + 1] = m_pList[k];
}
m_pList[i] = *e;
m_iLength++;
return true;
}
{
if (i < 0 || i > m_iLength || m_iLength == m_iSize || ((i != 0) && ListEmpty()))
{
return false;
}
for (int k = m_iLength - 1; k >= i; k--)
{
m_pList[k + 1] = m_pList[k];
}
m_pList[i] = *e;
m_iLength++;
return true;
}
2017-06-07
bool List::ListInsert(int i, Elem *e) //i的意思并不是下标,而是第i个元素
{
if (i < 0 || i > m_iLength || m_iLength == m_iSize)
{
return false;
}
for (int k = m_iLength - 1; k >= i; k--)
{
m_pList[k + 1] = m_pList[k];
}
m_pList[i] = *e;
m_iLength++;
return true;
}
我觉得插入代码应该这样写
{
if (i < 0 || i > m_iLength || m_iLength == m_iSize)
{
return false;
}
for (int k = m_iLength - 1; k >= i; k--)
{
m_pList[k + 1] = m_pList[k];
}
m_pList[i] = *e;
m_iLength++;
return true;
}
我觉得插入代码应该这样写
2017-06-07
bool List::PriorElem(int *currentElem, int *preElem)
{
int temp = LocateItem(currentElem);
if (-1 == temp || 0 == temp)
{
return false;
}
else
{
*preElem = m_pList[temp - 1];
return true;
}
}
其实这样也可以,都行
{
int temp = LocateItem(currentElem);
if (-1 == temp || 0 == temp)
{
return false;
}
else
{
*preElem = m_pList[temp - 1];
return true;
}
}
其实这样也可以,都行
2017-06-07
考虑全一点
if(i < 0 || i > m_iLength-1 || m_iSize - m_iLength == 0)
{
return false;
}
if(i < 0 || i > m_iLength-1 || m_iSize - m_iLength == 0)
{
return false;
}
2017-05-31