if (isPrime ==1)
要放在循环后面而不是里面
“Struct.h”
#pragma once
#include<iostream>
#include<string>
using namespace std;
#include<cstdlib> //C语言标准库函数,包含随机函数rand()srand(number);
#include<ctime> //time函数头文件
#define MinSize 20
#define MinddleSize 100
#define MaxSize 500
typedef struct {
int key;
//string name; 先做保留
}Redtype;
typedef struct {
Redtype r[MinSize + 1];
int length;
int countMove = 0;
int countCompare= 0 ;
}Sqlist1;
typedef struct {
Redtype r[MinddleSize + 1];
int length;
int countMove = 0;
int countCompare = 0;
}Sqlist2;
typedef struct {
Redtype r[MaxSize + 1];
int length;
int countMove = 0;
int countCompare = 0;
}Sqlist3;
void CreateList(Sqlist1 &L) {
L.length = 0;
srand(int(time(0)));
for (int i = 1; i <= MinSize; i++) {
L.r[i].key = rand() % 100;
L.length++;
}
}
void CreateList(Sqlist2 &L) {
L.length = 0;
srand(int(time(0)));
for (int i = 1; i <= MinddleSize; i++) {
L.r[i].key = rand() % 100;
L.length++;
}
}
void CreateList(Sqlist3 &L) {
L.length = 0;
srand(int(time(0)));
for (int i = 1; i <= MaxSize; i++) {
L.r[i].key = rand() % 100;
L.length++;
}
}
void ShowList(Sqlist1 L) {
for (int i = 1; i <= L.length; i++) {
cout << L.r[i].key << " ";
if (i % 20 == 0) //每行20个
cout << endl;
}
cout << "\n比较次数为:" << L.countCompare << endl;
cout << "移动次数为: " << L.countMove << endl;
}
void ShowList(Sqlist2 L) {
for (int i = 1; i <= L.length; i++) {
cout << L.r[i].key << " ";
if (i % 20 == 0) //每行20个
cout << endl;
}
cout << "\n比较次数为:" << L.countCompare << endl;
cout << "移动次数为: " << L.countMove << endl;
}
void ShowList(Sqlist3 L) {
for (int i = 1; i <= L.length; i++) {
cout << L.r[i].key << " ";
if (i % 20 == 0) //每行20个
cout << endl;
}
cout << "\n比较次数为:" << L.countCompare << endl;
cout << "移动次数为: " << L.countMove << endl;
}