- 论坛徽章:
- 0
|
插入排序的一个源程序
我改好了,正确的源程序如下:
- #include <iostream.h>;
- #include <conio.h>;
- const int maxsize=5;
- typedef struct {
- int key;
- char *keyinfo;
- }redtype;
- redtype *r[maxsize+1];
- void init()
- {int i;
- r[0]=new redtype;
- r[0]->;key=0;
- r[0]->;keyinfo="d";
- cout<<"please input the data value:"<<endl;
- for (i=0;i<maxsize;i++)
- {
- r[i+1]=new redtype;
- cin>;>;r[i+1]->;key;
- r[i+1]->;keyinfo="d";
- };
- };
- void insertsort()
- {
- extern int lt(int a,int b);
- int j;
- for(int i=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>;0);--j)
- {r[j+1]->;key=r[j]->;key;
- }
- r[j+1]->;key=r[0]->;key;
- }
- }
- };
- int lt(int a,int b)
- {if (a>;b)
- return 0;
- else
- return 1;
- };
- void display()
- {int i;
- cout<<"the list of sorted data is:";
- for (i=1;i<=maxsize;i++)
- cout<<r[i]->;key<<" ";
- };
- main()
- {extern void init();
- extern void insertsort();
- extern int lt(int a,int b);
- extern void display();
- init();
- insertsort();
- display();
- getch();
- }
-
复制代码 |
|