赞
踩
- #include <string>
- #include <stdio.h>
- #include <iostream>
- using namespace std;
-
- typedef struct Node
- {
- int data;
- Node * next;
- }Node;
-
- void swap(Node * A, Node *B)
- {
- cout<<"swap before :"<<A->data<<" "<<B->data<<endl;
- int temp= A->data;
- A->data=B->data;
- B->data=temp;
- cout<<"swap after :"<<A->data<<" "<<B->data<<endl;
- }
-
-
- Node* getSeperator(Node * begin, Node * end)
- {
- Node * p = begin;
- Node * q = begin->next;
- int key = p->data;
- while(q!=end)
- {
- if(q->data <key)
- {
- p=p->next;
- swap(p,q);
- }
- q=q->next;
- }
- swap(begin,p);
- return p;
- }
-
- void quicksort(Node * begin , Node * end)
- {
- cout<<"sort begin";
- if(begin!=end)
- {
- Node* sep= getSeperator(begin,end);
- quicksort(begin,sep);
- if (sep != end) {
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。