模版快拍
来源:互联网 发布:淘宝48分店铺解封 编辑:程序博客网 时间:2024/04/18 14:48
template<typename T> struct Node { T m_Data; Node * m_pNext; }; template<typename T> void ListQuickSort(Node<T> * pHead, Node<T> * pEnd/*尾结点可以为空*/) { T Key; T Tmp; Node<T> * pLow = NULL; Node<T> * pHigh = NULL; if (!pHead) return ; if (pHead == pEnd) return; pLow = pHead; pHigh = pHead->m_pNext; Key = pHead->m_Data; while (pHigh != pEnd) { if (pHigh->m_Data < Key) { pLow = pLow->m_pNext; Tmp = pLow->m_Data; pLow->m_Data = pHigh->m_Data; pHigh->m_Data = Tmp; } pHigh = pHigh->m_pNext; } Tmp = pHead->m_Data; pHead->m_Data = pLow->m_Data; pLow->m_Data = Tmp; ListQuickSort(pHead, pLow); ListQuickSort(pLow->m_pNext, pEnd); }
#include <time.h> #include <iostream> using namespace std; void main() { int i = 0; Node<int> * pInt = NULL; Node<int> * pNewNode = NULL; Node<int> * pCurNode = NULL; srand(time(NULL)); for (i = 0; i < 10; i++) { pNewNode = new Node<int>; if (pNewNode == NULL) { while (pInt) { pCurNode = pInt; pInt = pInt->m_pNext; delete pCurNode; } pInt = NULL; return; } pNewNode->m_Data = rand() % 100; pNewNode->m_pNext = pInt; pInt = pNewNode; } cout << "排序前:" << endl; pCurNode = pInt; while (pCurNode) { cout << pCurNode->m_Data << '\t'; pCurNode = pCurNode->m_pNext; } cout << endl; ListQuickSort<int>(pInt, NULL); cout << "排序后:" << endl; pCurNode = pInt; while (pCurNode) { cout << pCurNode->m_Data << '\t'; pCurNode = pCurNode->m_pNext; } cout << endl; while (pInt) { pCurNode = pInt; pInt = pInt->m_pNext; delete pCurNode; } pInt = NULL; _CrtDumpMemoryLeaks(); system("pause"); return; }
0 0
- 模版快拍
- 快拍
- 快拍 bt
- 快拍算法
- C泛型编程实现的快排模版
- 模版
- 模版
- 模版
- 模版
- 模版
- 模版
- 模版
- 模版
- 模版
- 模版
- 模版
- 模版
- 快
- This application has requested the Runtime to terminate it in an unusual way
- 跨站请求伪造(CSRF)——常见网站攻击手段原理与防御
- 丢手帕问题(Josephus问题)
- jquery监听滚动条,实现“返回顶部”
- 中国人民保险车险理赔
- 模版快拍
- android之自定义控件一控件的呈现机制
- 二分插入排序(BinaryInsertSort)
- 内部类分类介绍JAVA224-225
- 环形队列
- 为AM335x移植 Linux内核dts ---fwqlzz love is for ever
- C#学习总结
- 【一天一道LeetCode】#14 Longest Common Prefix
- [LeetCode]128. Longest Consecutive Sequence