#include<stack>
#include "List.h" void PrintListReversingly_Iteratively(ListNode* pHead)
{
std::stack<ListNode*> nodes; ListNode* pNode = pHead;
while (pNode != nullptr)
{
nodes.push(pNode);
pNode = pNode->m_pNext;
} while (!nodes.empty())
{
pNode = nodes.top();
printf("%d\t", pNode->m_nValue);
nodes.pop();
}
} void PrintListReversingly_Recursively(ListNode* pHead)
{
if (pHead != nullptr)
{
if (pHead->m_pNext != nullptr)
{
PrintListReversingly_Recursively(pHead->m_pNext);
}
printf("%d\t", pHead->m_nValue);
}
} void Test(ListNode* pHead)
{
PrintList(pHead);
PrintListReversingly_Iteratively(pHead);
printf("\n");
PrintListReversingly_Recursively(pHead);
} // 1 2 3 4 5
void Test1()
{
printf("\nTest1 begins.\n"); ListNode* pNode1 = CreateListNode();
ListNode* pNode2 = CreateListNode();
ListNode* pNode3 = CreateListNode();
ListNode* pNode4 = CreateListNode();
ListNode* pNode5 = CreateListNode(); ConnectListNodes(pNode1, pNode2);
ConnectListNodes(pNode2, pNode3);
ConnectListNodes(pNode3, pNode4);
ConnectListNodes(pNode4, pNode5); Test(pNode1); DestroyList(pNode1);
} // only one node
void Test2()
{
printf("\nTest2 begins.\n"); ListNode* pNode1 = CreateListNode(); Test(pNode1);
DestroyList(pNode1);
} // empty list
void Test3()
{
printf("\nTest3 begins.\n");
Test(nullptr);
} int main()
{
Test1();
Test2();
Test3(); return ; }