数据结构课程设计
附录 源程序清单
#include<iostream.h> #include<iomanip.h> #include<stdlib.h> #include<stdio.h> #include<time.h> #define N 100 int p,q; //起泡排序
void gensort(int b[],int n) {
int i,j;int s=0,t=0; for(i=0;i<n-1;i++) {
for(j=i+1;j<n;j++) { t++;
if(b[i]>b[j]) {
int temp=b[i]; b[i]=b[j]; b[j]=temp; s+=3; }}}
cout<<"移动次数="<<s<<","<<"比较次数="<<t<<endl; }
//插入排序
typedef int KeyType;
struct rec {
KeyType key; };
typedef rec sqlist[N];
void insertsort(sqlist b,int n) {
int i,j;int s=0,t=0; for(i=2;i<n;i++)
14