房天下 > 房天下问答 > 业主生活 > 其他
  • 三道C++习题,高额悬赏

    1编写程序验证"插入排序"的基本功能目的: 从键盘输入整数 用inser_srot按递增排序 输出排序后的结果 输入: 3 2 1 4 ^Z 输出: [1,2,3,4,] 2编写程序验证"Shell Sort"的基本功能目的: 从键盘输入整数,以ctrl+Z结束 输出shell sort每一步的结果 输入: 3 2 4 1 ^Z 输出: [3,1,4,2,] // delta = 2 [1,2,3,4,] // delta = 1 3编写程序验证"Bubble Sort"的基本功能目的: 从键盘输入整数,以ctrl+Z结束 输出Bubble sort每一步的结果 输入: 3 2 4 1 ^Z 输出: [2,3,1,4,] [2,1,3,4,] [1,2,3,4,]

    提问者:安聊海阔

    发布于2011-01-12

共1个回答
  • oyangbing 丨Lv 0
    我这里就只写插入排序了,如果另外那两个还想我再回答一遍的话,我可以在这里再写一遍:插入排序代码如下:#include<iostream>#define MAX 100using namespace std;void main(){ int size=0; int input[MAX]; int i,j,temp; int haschange; while(size<MAX && cin>>input[size]) size++; for(i=1;i<size;i++) { haschange=0; for(j=i;j>0;j--) { if(input[j]>input[j-1]) { haschange=1; break; } temp=input[j]; input[j]=input[j-1]; input[j-1]=temp; } if(haschange) continue; for(j=0;j<size;j++) cout<<input[j]<<" "; cout<<endl; } cout<<"结束排序!"<<endl; cout<<"当前顺序为:"<<endl; for(i=0;i<size;i++) cout<<input[i]<<" "; cout<<endl;}
    +1 2011-01-13 举报
热门人气推荐
免责声明:问答内容均来源于互联网用户,房天下对其内容不负责任,如有版权或其他问题可以联系房天下进行删除。