![](https://img-blog.csdnimg.cn/20201014180756757.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
排序
JohnWill_
小白一个,慢慢成长....
展开
-
链表排序Sort_List(归并)
题目:Sort a linked list in O(n log n) time using constant space complexity.因为题目要求复杂度为O(nlogn),故可以考虑归并排序的思想。 归并排序的一般步骤为: 1)将待排序数组(链表)取中点并一分为二; 2)递归地对左半部分进行归并排序; 3)递归地对右半部分进行归并排序; 4)将两个半部分进行合并(m...原创 2018-03-19 21:46:51 · 221 阅读 · 0 评论 -
链表插入排序
题目: Sort a linked list using insertion sort.给单链表排序(升序排列,要保持稳定性),要求通过改变结点的next指针从而改变结点的位置,而不是只交换结点的值来使得其有序!时间复杂度为O(N^2),空间复杂度为O(1)。这个算法的思想是这样的: 1. 维护两部分,一是已排序的部分,一是待排序的部分; 2. 一开始已排序部分为NULL; 3. 每次取出待排序部...原创 2018-03-20 11:15:47 · 144 阅读 · 0 评论 -
二叉树中序遍历
题目描述Given a binary tree, return the inorder traversal of its nodes' values. For example: Given binary tree{1,#,2,3}, 1 \ 2 / 3 return[1,3,2]. Note: Recursive solution is trivial...原创 2018-03-29 21:57:06 · 107 阅读 · 0 评论 -
二叉树后序遍历(栈)
题目:Given a binary tree, return the postorder traversal of its nodes' values.For example:Given binary tree{1,#,2,3}, 1 \ 2 / 3 return[3,2,1].Note: Recursive solution is trivial, could...原创 2018-03-20 14:29:55 · 3834 阅读 · 0 评论 -
二叉树前序遍历(栈)
题目:Given a binary tree, return the preorder traversal of its nodes' values.For example:Given binary tree{1,#,2,3}, 1 \ 2 / 3 return[1,2,3].Note: Recursive solution is trivial, could ...原创 2018-03-20 15:41:48 · 907 阅读 · 0 评论