#include "stdio.h"
#include "stdlib.h"
#include "Node.h"
#include "OrderedList.h"
#include "OrderedSet.h"
void Initialization()
{
//系统初始化
OrderedSet Set1,Set2;
char s[100];
system("cls"); //清屏
printf("*******************************************************************************\n");
printf("MakeSet1--1 MakeSet2--2 Union--u Initialization--i Difference--d Quit--q;\n");
printf("*******************************************************************************\n");
CreateSet(Set1,s); PrintSet(Set1); //构造并显示空集Set1
CreateSet(Set2,s); PrintSet(Set2); //构造并显示空集Set2
}//Initialization
void Interpret(char cmd,OrderedSet &Set1,OrderedSet &Set2)
{
//解释执行操作命令cmd
OrderedSet T;
char s[100];
switch (cmd){
case '1':printf("请以串的形式输入集合Set1\n");
scanf("%s",&s); //读入集合元素到串变量v
CreateSet(Set1,s);
PrintSet(Set1); //构造并显示有序集Set1
printf("\n");
break;
case '2':printf("请以串的形式输入集合Set2\n");
scanf("%s",&s); //读入集合元素到串变量v
CreateSet(Set2,s); PrintSet(Set2); //构造并显示有序集Set2
printf("\n");
break;
case 'u':Union(T,Set1,Set2); //求有序集Set1和Set2的并集T
PrintSet(T);
printf("集合Set1和Set2的并集\n");//显示并集T
DestroyList(T); //销毁并集T
break;
case 'i':Intersection(T,Set1,Set2); //求有序集Set1和Set2的交集T
PrintSet(T);
printf("集合Set1和Set2的交集\n");
DestroyList(T);
break;
case 'd':Difference(T,Set1,Set2); //求有序集Set1和Set2的差集T
PrintSet(T);
printf("集合Set1和Set2的差集\n");
DestroyList(T);
break;
}
}//Interpret
void main()
{//主函数
char cmd;
Initialization(); //初始化
printf("输入要执行的操作:");
OrderedList Set1,Set2;
char s[100];
CreateSet(Set1,s);
CreateSet(Set2,s);
do {//读入一个操作命令符
scanf("%c",&cmd);
Interpret(cmd,Set1,Set2); //解释执行操作命令符
} while (cmd!='q');
getchar();
}//main
- 1
- 2
前往页