栈的压入、弹出序列
摘要:bool IsPopOrder(const int* pPush, const int* pPop, int nLength) { if (pPush == nullptr || pPop == nullptr || nLength <= 0) return false; std::stack<in
阅读全文
posted @
2021-02-18 14:21
Noora&w
阅读(53)
推荐(0)
包含min函数的栈
摘要:std::stack<int> m_data; std::stack<int> m_min; //辅助栈 template <typename T> void StackWithMin<T>::push(const T& value) { m_data.push(value); if (m_min.
阅读全文
posted @
2021-02-18 10:37
Noora&w
阅读(54)
推荐(0)
顺时针打印矩阵
摘要:void PrintMatrixClockwise(int** arr, int columns, int rows) { if (arr == nullptr || columns <= 0 || rows <= 0) return; int start = 0; while (columns >
阅读全文
posted @
2021-02-16 21:53
Noora&w
阅读(35)
推荐(0)
二叉树的镜像
摘要:void MirrorRecursively(BinaryTreeNode* pRoot) { if (pRoot == nullptr || (pRoot->m_pLeft == nullptr && pRoot->m_pRight == nullptr)) return; BinaryTreeN
阅读全文
posted @
2021-02-16 21:03
Noora&w
阅读(49)
推荐(0)
树的子结构*
摘要:struct BinaryTreeNode { int m_nValue; BinaryTreeNode* m_pLeft; BinaryTreeNode* m_pRight; }; bool HasSubTree(BinaryTreeNode* pRoot1, BinaryTreeNode* pR
阅读全文
posted @
2021-02-16 20:53
Noora&w
阅读(22)
推荐(0)
调整数组顺序使奇数位于偶数前面
摘要:void ReorderOldEven(int* arr, unsigned int length) { if (arr == nullptr || length == 0) return; int* pBegin = arr; int* pEnd = arr + length - 1; while
阅读全文
posted @
2021-02-16 15:18
Noora&w
阅读(61)
推荐(0)
在O(1)时间内删除链表节点
摘要:struct ListNode { int nValue; ListNode* pNext; }; void DeleteListNode(ListNode* pHeadNode, ListNode* pDeleteNode) { if (!pHeadNode || !pDeleteNode) re
阅读全文
posted @
2021-02-08 17:31
Noora&w
阅读(50)
推荐(0)
打印1到最大的n位数*
摘要:注意:需考虑大数问题 方法一: void PrintFrom1ToMax(int n) { if (n <= 0) return; char* arrPrintStr = new char[n+1]; memset(arrPrintStr, '0', n); arrPrintStr[n] = '\0
阅读全文
posted @
2021-02-08 15:32
Noora&w
阅读(93)
推荐(0)
数值的整数次方*
摘要:bool g_bInvalidInput = false; double power(double base, int exponent) { if (equal(base, 0.0) && exponent < 0) { g_bInvalidInput = true; return 0.0; }
阅读全文
posted @
2021-02-07 17:45
Noora&w
阅读(41)
推荐(0)
员工年龄排序
摘要:void AgeSort(int arrAges[], int nLength) { const int nAgeMax = 99; int arrTemp[nAgeMax+1]; for (int i = 0; i < nAgeMax; ++i) { arrTemp[i] = 0; } for (
阅读全文
posted @
2021-02-07 15:03
Noora&w
阅读(78)
推荐(0)
重建二叉树*
摘要:struct BinaryTreeNode { int nValue; BinaryTreeNode* pLeft; BinaryTreeNode* pRight; }; BinaryTreeNode* ConstructCore(int* startPreorder, int* endPreord
阅读全文
posted @
2021-01-26 15:53
Noora&w
阅读(60)
推荐(0)
从尾到头打印链表
摘要://栈 void printList(ListNode* pHead) { std::stack<ListNode*> printStack; ListNode* pTemp = pHead; while (pTemp != nullptr) { printStack.push(pTemp); pT
阅读全文
posted @
2021-01-21 19:59
Noora&w
阅读(51)
推荐(0)
替换空格
摘要:void replace(char* data, int length) { if (data == nullptr || length <= 0) return; int nEmptyNumber = 0; int nOrignialLength = 0; int i = 0; while(dat
阅读全文
posted @
2021-01-21 17:31
Noora&w
阅读(142)
推荐(0)
二维数组中的查找
摘要:bool find(int* data, int rows, int columns, int number) { if (data == nullptr || rows <= 0 || columns <= 0) return false; bool bfind = false; int row
阅读全文
posted @
2021-01-21 15:04
Noora&w
阅读(59)
推荐(0)
单例模式
摘要://饿汉模式:即类产生的时候就创建好实例对象,这是一种空间换时间的方式 class CSingleton { public: ~CSingleton() {}; CSingleton(const CSingleton&); CSingleton& operator=(const CSingleton
阅读全文
posted @
2021-01-21 11:45
Noora&w
阅读(53)
推荐(0)
赋值运算符函数
摘要:已知类: class CMyString { public: CMyString(char* pData = NULL); CMyString(const CMyString& str); ~CMyString(void); private: char* m_pData; }; 初级实现: CMyS
阅读全文
posted @
2021-01-20 15:24
Noora&w
阅读(130)
推荐(0)
用两个栈实现队列
摘要:题目:用两个栈来实现一个队列,完成队列的Push和Pop操作。 队列中的元素为int类型 思路:画图分析
阅读全文
posted @
2018-05-21 19:20
Noora&w
阅读(105)
推荐(0)
合并两个排序的链表
摘要:题目:输入两个单调递增的链表,输出两个链表合成后的链表,当然我们需要合成后的链表满足单调不减规则 思路:比较得到两个链表中值较小的头节点并把它链接到已经合并的链表之后,两个链表剩余的节点依然是排序的,因此合并的步骤和之前的步骤一样,这是典型的递归过程。
阅读全文
posted @
2018-05-21 18:38
Noora&w
阅读(108)
推荐(0)
反转链表
摘要:题目:输入一个链表,反转链表后,输出链表的所有元素 思路:使用三个指针遍历一遍链表 注意:代码的鲁棒性!
阅读全文
posted @
2018-05-21 18:09
Noora&w
阅读(107)
推荐(0)
链表倒数第k个节点
摘要:题目:输入一个链表,输出该链表中倒数第k个结点 思路:1.遍历两遍链表,第一遍找到链表长度n,第二遍从0到n-k+1找到倒数第k个节点,不是最优解。 2.使用两个指针,只需遍历一遍链表。第一个指针先走k-1步,然后两个指针同时向后遍历,当第一个指针走到尾节点时,第二个指针刚好在倒数第k个节点上。 注
阅读全文
posted @
2018-05-21 17:48
Noora&w
阅读(108)
推荐(0)