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