| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1078 人关注过本帖
标题:我把书上的“快速排序”(QuickSort)编程实现了,但是出错了,可以帮我看看 ...
只看楼主 加入收藏
kappa314
Rank: 1
等 级:新手上路
帖 子:43
专家分:0
注 册:2004-10-9
收藏
 问题点数:0 回复次数:1 
我把书上的“快速排序”(QuickSort)编程实现了,但是出错了,可以帮我看看吗?

error C2601: 'main' : local function definitions are illegal

fatal error C1004: unexpected end of file found

#include"iostream" #include"iomanip" using namespace std; void Swap(int &a,int &b){//交换 int temp; temp=a; a=b; b=temp; }//Swap int PivotList(int list[],int first,int last){ int pivotValue,pivotPoint,index; pivotValue=list[first];//用来存储pivot的值 pivotPoint=first;//pivot地址下标 for(index=first+1;index<=last;index++) if(list[index]<pivotValue){ pivotPoint=pivotPoint+1; Swap(list[pivotPoint],list[index]); }//if Swap(list[first],list[pivotPoint]); return pivotPoint; }//PivotList void QuickSort(int List[],int First,int Last){ int i,pivot;//区分>pivot和<pivot的元素 if(First<Last){ pivot=PivotList(List,First,Last); QuickSort(List,First,pivot-1); QuickSort(List,pivot+1,Last); }//if cout<<"The new list is:\n"; for(i=1;i<=100;i++){ cout<<setw(2)<<List[i]<<" "; if(i%10==0) cout<<"\n"; }//QuickSort int main(){ int a[101],i,endFlag; a[0]=0; for(i=1;i<101;i++){ a[i]=rand()%100; a[0]++; }//for cout<<"\nThe original elements are:\n"; for(i=1;i<101;i++){ cout<<setw(2)<<a[i]<<" "; if(i%10==0) cout<<"\n"; }//for cout<<endl<<endl; QuickSort(a,1,100);//1=>first,100=>end cout<<"\nEnd?OK,please press 1 \n";//使用endFlag作为结束前的标志 cin>>endFlag; return 0; }//main

搜索更多相关主题的帖子: QuickSort 
2004-11-22 18:05
时空之蕊
Rank: 2
等 级:新手上路
威 望:3
帖 子:691
专家分:0
注 册:2004-10-31
收藏
得分:0 
main前面少了一个}

我渴望掌控时空的核心——用最先进的技术,打造无比美丽的世界!
2004-11-22 19:09
快速回复:我把书上的“快速排序”(QuickSort)编程实现了,但是出错了,可以帮 ...
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.014574 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved