栈的压入、弹出序列
摘要: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
阅读(55)
推荐(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
阅读(55)
推荐(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
阅读(50)
推荐(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
阅读(24)
推荐(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
阅读(63)
推荐(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
阅读(52)
推荐(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
阅读(96)
推荐(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
阅读(80)
推荐(0)