![](https://img-blog.csdnimg.cn/20201014180756927.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
算法
Edisonlhz
初入编程,深似海!
展开
-
最大子序列和
最大子序列和有几种时间复杂度的实现方法,本文在此列举先行实现方法:原创 2014-11-10 21:50:33 · 285 阅读 · 0 评论 -
归并排序的一点见解
归并排序void Merge(int a[],int term[],int first,int last){ int mid = (first+last)>>1; int i = first; int j = mid + 1; int k = 0; while(i<=mid&&j<=last) { if(a[i]<=a[j]) term[k++] = a[i++];原创 2014-11-19 11:43:27 · 343 阅读 · 0 评论 -
判断循环链表
通过两个指针,一个每次递增一步(slow),一个每次递增两步(fast),如果两个指针相遇代表有循环。bool hasCycle(ListNode *head) { ListNode *slow = head; ListNode *fast = head; while (slow != NULL && fast != NULL && fa原创 2016-05-27 10:04:11 · 282 阅读 · 0 评论 -
替换字符串空格
本算法通过从后遍历字符串实现O(n)的时间复杂度替换字符串中的空格。void replaceSpace(char *str, int maxLength){ int length = strlen(str); int spaceNum = 0; for (int i = 0; i < length; i++) { if (str[i] == ' ') { spaceNu原创 2016-05-17 17:31:44 · 255 阅读 · 0 评论 -
用两个栈实现队列
#include <stack>template <typename T>class CQueue{public: CQueue(void){} ~CQueue(){} void appendTail(const T& node); T deleteHead();private: std::stack<T> stack1; std::stack<原创 2016-05-18 20:05:11 · 213 阅读 · 0 评论 -
用两个队列实现栈
#include template class CStack{public: void AddToTail(const T&); T deleteHead();private: std::queue queue1; std::queue queue2;};template void CStack::AddToTail(const T& value){ queue1.p原创 2016-05-18 20:06:49 · 240 阅读 · 0 评论 -
合并有序链表
ListNode* mergeList(ListNode* pHead1, ListNode* pHead2){ if (pHead1 == NULL) { return pHead2; } else if (pHead2 == NULL) { return pHead1; } ListNode* pMergeHead = NULL; if (pHead1->m_nVal原创 2016-07-13 11:37:16 · 365 阅读 · 0 评论