1
0
Fork 0
You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

84 lines
2.6 KiB
C++

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#include "AlgPerf.h"
#include "Benchmark.h"
#include "LinkedList.h"
int main()
{
//benchmark_hw3_2(5, 600, 5, 200);
/* 测试结点类ListNode
1.1 ListNode函数
1.2 ~ListNode()函数 */
LinkNode<int> myNode3(6), myNode2(0, &myNode3), myNode1(7, &myNode2), *first = &myNode1;
LinkNode<int> *p3 = new LinkNode<int>(6, NULL);
LinkNode<int> *p2 = new LinkNode<int>(0, p3);
LinkNode<int> *p1 = new LinkNode<int>(7, p2);
delete p1; //调用p1所指结点的析构函数
delete p2; //调用p2所指结点的析构函数
delete p3; //调用p3所指结点的析构函数
/* 测试单链表类LinkedList
2.1、inputFront函数或inputRear函数
2.2、Remove函数
2.3、output()函数
*/
LinkedList<int> myList;
//int j,n=10;
int x;
myList.input(); //输入1 0 <enter> 10 9 8 7 6 5 4 3 2 1 0 <enter>
myList.output();
myList.Remove(4, x);
myList.output();
/* 作业测试一(功能测试+高效性测试单链表类LinkedList<T>:: Uniquify操作
Uniquify()操作有比较元素值和元素移动两种基本操作,
测试方法是分别对随机生成的大小为 5 - 600 (间隔为 5的200个有序数组进行Uniquify操作测试,结果输出在Uniquify.txt文件里*/
//void timeAlg(FILE *fp, int incN, int maxN, int numTrials, char *partitionAlg); //函数声明
int incN = 5; //设置数组初始长度
int maxN = 600;
int numTrials = 200; //测试次数
char Alg[20] = "Uniquify"; //算法的名称
char outFileName[20]; //测试结果存放的文件名
FILE *fp;
errno_t err;
//创建一个名为Alg的txt文件
strcpy_s(outFileName, Alg);
strcat_s(outFileName, ".txt");
err = fopen_s(&fp, outFileName, "w+");
printf("# Results for %d 次测试", numTrials);
printf("# n time (msec)");
printf("# ---------------\n");
//统计Alg算法对大小为incN2*incN,3*incN,...,maxN的数组进行一次操作的时间
timeAlg(fp, incN, maxN, numTrials);
fclose(fp);
printf("done! results in %s\n\n\n\n", Alg);
cout << "作业测试第二部分(功能测试):" << endl;
int i, test[10] = {6, 5, 3, 8, 2, 7, 1, 9, 4, 4};
LinkedList<int> OrderList1, OrderList2, OrderList3, List1;
for (i = 0; i < 10; i++)
{
List1.Insert(i, test[i]);
}
//List1.Sort();
List1.output(); //output: 6 5 3 8 2 7 1 9 4 4
for (i = 0; i < 4; i++)
{
OrderList1.OrderInsert(test[i]);
}
OrderList1.output(); //输出: 3,5,6,8
for (i = 4; i < 10; i++)
{
OrderList2.OrderInsert(test[i]);
}
OrderList2.output(); //输出1,2,4,4,7,9
OrderList3.Merge(OrderList1, OrderList2);
OrderList3.output(); //应该输出:1,2,3,4,4,5,6,7,8,9
system("pause");
return 0;
}