分数少,可以说群,然后加入,在群里讨论c++吗?

StrongHello 2012-10-26 10:57:53
我实在是问题特别多。希望版主谅解。这个又错了,怎么错了。郁闷死了。这般查找。


#include<iostream.h>
#include<iomanip.h>
#define MAX 20
typedef int elemtype;
typedef elemtype recs[MAX];
void ssort(recs A,int n );
void main()
{
recs A={0,2,8,3,6,9,5,1,4,0,7};
int n=10,i;
cout <<"插入排序"<< endl <<"排序前:";
for(i=1;i<=n;i++)
cout << setw(3) << A[i];
cout <<endl;
ssort(A,n);
cout <<"排序后";
for(i=0;i<n;i++)
cout << setw(3) << A[i];
cout <<endl;
}

void ssort(recs B, int m)
{
int i,j,low,mid,high;
for(i=2;i<=m;i++)
{
low=1;high=i-1;mid=(low+high)/2;
B[0]=B[i];
while(low<=high)
{
if(B[0]>B[mid])
mid=low+1;
else
mid=high-1;
}
}
for(j=i-1;j>=high+1;j--)
B[j+1]=B[j];
B[high+1]=B[0];
}


...全文
95 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
qin_pp 2012-10-27
  • 打赏
  • 举报
回复
楼主的ssort函数有问题,双重循环出了问题,比较挑不出来,改了一下,但是逻辑上还有问题,但是可以运行结果了,再看看吧!
加了两条语句
#include<iostream.h>
#include<iomanip.h>
#define MAX 20
typedef int elemtype;
typedef elemtype recs[MAX];
void ssort(recs A,int n );
void main()
{
recs A={0,2,8,3,6,9,5,1,4,0,7};
int n=10,i;
cout <<"插入排序"<< endl <<"排序前:";
for(i=1;i<=n;i++)
cout << setw(3) << A[i];
cout <<endl;
ssort(A,n);
cout <<"排序后";
for(i=0;i<n;i++)
cout << setw(3) << A[i];
cout <<endl;
}

void ssort(recs B, int m)
{
int i,j,low,mid,high;
for(i=2;i<=m;i++)
{
low=1;high=i-1;mid=(low+high)/2;
B[0]=B[i];
while(low<=high)
{
if(B[0]>B[mid])
{ mid=low+1;
break;
}
else
{
mid=high-1;
break;
}
}
}
for(j=i-1;j>=high+1;j--)
B[j+1]=B[j];
B[high+1]=B[0];
}
virtualxmars 2012-10-27
  • 打赏
  • 举报
回复
StringHello~我是Charles,群里那个,把分乖乖交出来~嘿嘿
StrongHello 2012-10-27
  • 打赏
  • 举报
回复
#include<iostream.h>
#include<iomanip.h>
#define MAX 20
typedef int elemtype;
typedef elemtype recs;
void ssort(recs A[],int n );
void main()
{
recs A[]={0,2,8,3,6,9,5,1,4,0,7};
int n=10,i;
cout <<"插入排序"<< endl <<"排序前:";
for(i=1;i<=n;i++)
cout << setw(3) << A[i];
cout <<endl;
ssort(A,n);
cout <<"排序后";
for(i=1;i<=n;i++)
cout << setw(3) << A[i];
cout <<endl;
}

void ssort(recs B[], int m)
{
int i,j,low,mid,high;
for(i=2;i<=m;i++)
{
low=1;high=i-1;
B[0]=B[i];
while(low<=high)
{
mid=(low+high)/2;
if(B[0]>B[mid])
low=mid+1;
else
high=mid-1;

}

for(j=i-1;j>=high+1;j--)
B[j+1]=B[j];
B[high+1]=B[0];
}
}


StrongHello 2012-10-27
  • 打赏
  • 举报
回复
监察审计部门进行核实后,情节严重的可被刑事拘留

65,210

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧