leetcode——链表快排
来源:互联网 发布:电力工程计价软件 编辑:程序博客网 时间:2024/05/17 23:00
#include <iostream>using namespace std; struct ListNode { int val; ListNode *next; ListNode(int x) : val(x), next(NULL) {} }; class Solution {public: void swapp ( int & x,int &y){ int t = x; x = y; y = t; } void quickSort(ListNode * begin,ListNode * end){ //终止条件 if( begin == end || begin->next == end){ return; } //divide int pivot = begin->val; ListNode *p = begin; ListNode *q = begin->next; while ( q!= end){ if( q->val < pivot){ p = p->next; swapp(p->val,q->val); } q = q->next; } swapp(begin->val,p->val); //conquer quickSort( begin,p); quickSort(p->next,end); } ListNode *sortList(ListNode *head) { quickSort(head,NULL); return head; }};int main(){}
0 0
- leetcode——链表快排
- 开始刷刷Leetcode—leetcode第二题
- LeetCode —— Combinations
- LeetCode —— Triangle
- LeetCode —— Anagrams
- [leetcode] Subsets——@
- Permutations——LeetCode
- minimum_window_substring ——leetcode
- LeetCode——Candy
- LeetCode——Triangle
- LeetCode——Combinations
- LeetCode——Permutations
- *candy——leetcode
- gas_station——leetcode
- LeetCode——Candy
- LeetCode——Triangle
- LeetCode——Anagrams
- LeetCode——Subsets
- Java容器类
- 查看ADB被占的PID
- 读C#线程方面知识做笔记
- win764位 jdk32位 android studio的使用
- poj 3740 dfs
- leetcode——链表快排
- 深度思维:网络推广绝不是千篇一律?
- 单例设计模式(饿汗式,懒汉式)
- C++ String写时拷贝(Copy On Write)
- 基于QT和opencv的摄像头(本地图片)读取并输出程序
- 我的Linux日常命令
- 蛤玮的机房
- HTTP返回码总结
- hotspot虚拟机中的对象是如何布局的