Code/Resource
Windows Develop
Linux-Unix program
Internet-Socket-Network
Web Server
Browser Client
Ftp Server
Ftp Client
Browser Plugins
Proxy Server
Email Server
Email Client
WEB Mail
Firewall-Security
Telnet Server
Telnet Client
ICQ-IM-Chat
Search Engine
Sniffer Package capture
Remote Control
xml-soap-webservice
P2P
WEB(ASP,PHP,...)
TCP/IP Stack
SNMP
Grid Computing
SilverLight
DNS
Cluster Service
Network Security
Communication-Mobile
Game Program
Editor
Multimedia program
Graph program
Compiler program
Compress-Decompress algrithms
Crypt_Decrypt algrithms
Mathimatics-Numerical algorithms
MultiLanguage
Disk/Storage
Java Develop
assembly language
Applications
Other systems
Database system
Embeded-SCM Develop
FlashMX/Flex
source in ebook
Delphi VCL
OS Develop
MiddleWare
MPI
MacOS develop
LabView
ELanguage
Software/Tools
E-Books
Artical/Document
ch7_11.cpp
Package: c.rar [view]
Upload User: puke2000
Upload Date: 2022-07-25
Package Size: 912k
Code Size: 1k
Category:
CSharp
Development Platform:
Visual C++
- //**********************
- //** ch7_11.cpp **
- //**********************
- #include <iostream.h>
- void qsort(int[],int,int);
- void main()
- {
- int array[]={55,2,6,4,11,12,9,73,26,37};
- int len=sizeof(array)/sizeof(int);
- for(int i=0; i<len; i++) //原始顺序输出
- cout <<array[i] <<",";
- cout <<endl <<endl;
- qsort(array,0,len-1); //调用排序函数
- for(int i=0; i<len; i++) //排序结果输出
- cout <<array[i]<<",";
- cout <<endl;
- }
- void qsort(int a[],int left,int right) //快速排序法
- {
- int pivot=a[right],l=left,r=right,temp;
- while(l<r){
- temp=a[l], a[l]=a[r], a[r]=temp; //交换
- while(l<r && a[r]>pivot) --r;
- while(l<r && a[l]<=pivot) ++l;
- }
- temp=a[left], a[left]=a[r], a[r]=temp; //使得a[r]成为分界元
- if(left<r-1) qsort(a,left,r-1);
- if(r+1<right) qsort(a,r+1,right);
- }