摘要:
#include//思路:遍历链表过程中,将各个指针入栈,再出栈进行反转ListNode* ReverseList(ListNode* pHead){ if(pHead == NULL) return NULL; ListNode* pNode = pHead; stack pNodeStack; while(pNode != NULL) { pNodeStack.push(pNode); pNode = pNode->m_pNext; } pNode = pNodeStack.top(); Li... 阅读全文
摘要:
感受:清晰的思路是最重要的!!!题目:求链表中间节点ListNode* MidNodeInList(ListNode* pHead){ if(pHead == NULL) return NULL; ListNode* pNode1 = pHead; ListNode* pNode2 = pHead; unsigned int step = 1; while(pNode2->m_pNext != NULL) { pNode2 = pNode2->m_pNext; step++; if((step & 0x... 阅读全文
摘要:
题目:打印单向链表中倒数第k个节点以下为自己所写代码,未经过验证,只是写个思路。。。#include#include#includeusing namespace std;//节点定义struct ListNode{ int m_nValue; ListNode* m_pNext;};void FindKthToTail(ListNode* pHead, unsigned int k){ if(pHead == NULL) throw new std::exception("Invalid parameters!"); std::vector Values... 阅读全文