- 论坛徽章:
- 0
|
插入排序的一个源程序
还有就是函数最后不用分号
()语句后都不用加分号
代码对齐后结果
- #include<iostream.h>;
- #include<conio.h>;
- voidinit();
- intlt(inta,intb);
- voidinsertsort();
- intlt(inta,intb);
- voiddisplay();
- typedefstruct{
- intkey;
- char*keyinfo;
- }redtype;
- constintmaxsize=5;
- redtype*r[maxsize+1];
- voidinit()
- {
- inti;
- r[0]=newredtype;
- r[0]->;key=0;
- r[0]->;keyinfo="d";
- for(i=0;i<maxsize;i++)
- {
- cout<<"pleaseinputthedatavalue:";
- r[i+1]=newredtype;
- cin>;>;r[i+1]->;key;
- r[i+1]->;keyinfo="d";
- }
- }
- voidinsertsort()
- {
- intj;
- for(inti=2;i<=maxsize;i++)
- {
- if(lt(r[i]->;key,r[i-1]->;key))
- {
- r[0]->;key=r[i]->;key;
- for(j=i-1;lt(r[0]->;key,r[j]->;key);--j)
- r[j+1]->;key=r[j]->;key;
- r[j+1]->;key=r[0]->;key;
- }
- }
- }
- intlt(inta,intb)
- {if(a>;b)
- return0;
- else
- return1;
- }
- voiddisplay()
- {inti;
- for(i=1;i<=maxsize;i++)
- cout<<"thelistofsorteddatais:";
- cout<<r[i]->;key<<",";
- }
- main()
- {
- init();
- insertsort();
- display();
- getch();
- }
-
复制代码 |
|