if (pLinkList == nullptr)
{
pLinkList = pP;
pP->pNext = nullptr;
}
else
{ // The linked list already exist, push the person object onto the list
pAdr = pLinkList;
// Go to the end of the List
while(pAdr->pNext != nullptr)
{
pAdr = pAdr->pNext;
}
// Push person object onto the List
pAdr->pNext = pP;
pP->pNext = nullptr;
}
if (pLinkList != nullptr)
{
pAdr = pLinkList;
if (pAdr->pNext == nullptr)
{ // Delete the beginning (Head) of the Linked List
delete pAdr;
pLinkList = nullptr;
return;
}
// Go to the next to last node in the list
while(pAdr->pNext->pNext != nullptr)
{
pAdr = pAdr->pNext;
}
// Pop person object of the List
delete pAdr->pNext;
pAdr->pNext = nullptr;
}
//*******************************************************************
// Function:Sort()
//*******************************************************************
void CLinkedList::Sort(void)
{
// Create a pointeer where we last inserted an object into the Linked List
CPerson* pLastSort = pLinkList;
char Alpha = 'A';
while(Alpha != 'Z')
{
// FindLName is just like function FindLastName, except
// we need to compare the first character in the Last Name,
// not the entire string.
CPerson* pP = FindLName(pLastSort, Alpha);
if (pP == nullptr)
{
Alpha++;
}
else
{
// Keep a pointer to the previous link which is pPrevious
// Defined globally to the class
// pLastSort is the place where we want to insert the object pP.
Disconnect(pP, pPrevious);
Insert(pLastSort, pP);
}
}
//*******************************************************************
// Function:Disconnect()
//*******************************************************************
void CLinkedList::Disconnect(CPerson* pP, CPerson* pPrevious)
{
// This step removed object pP from the Linked List
pPrevious->pNext = pP->pNext;
pP->pNext = nullptr;
return;
}
//*******************************************************************
// Function:FindLName()
//*******************************************************************
CPerson* CLinkedList::FindLName(CPerson* pLastSort, char Alpha)
{
// Do some work here.