This repository has been archived on 2024-01-06. You can view files and clone it, but cannot push or open issues or pull requests.
justhomework/DataStructure/Code/ex3/ex3.cpp

60 lines
1.5 KiB
C++
Raw Normal View History

2021-10-03 02:28:37 +00:00
#include <stdio.h>
#include <stdlib.h>
2021-10-29 08:51:54 +00:00
#include "vec.h"
2021-10-03 02:28:37 +00:00
int main()
{
2021-10-08 09:17:16 +00:00
int flag = 0;
int temp[5];
srand(time(NULL));
int len;
2021-10-29 08:51:54 +00:00
printf("输入生成数量\n");
2021-10-08 09:17:16 +00:00
scanf("%d", &len);
Vec v(len);
v.printall();
2021-10-03 02:28:37 +00:00
system("pause");
2021-10-29 08:51:54 +00:00
printf("排序:秩为%d\n",v.getused());
2021-10-15 07:20:32 +00:00
// v.bubbleSort();
v.mergeSort(0,v.getused());
2021-10-08 09:17:16 +00:00
v.printall();
while (1)
{
2021-10-29 08:51:54 +00:00
printf("选择操作:1.插入 2.删除 3.统计 4.退出\n");
2021-10-08 09:17:16 +00:00
scanf("%d", &flag);
switch (flag)
{
case 1:
2021-10-29 08:51:54 +00:00
printf("输入待插入数值\n");
2021-10-08 09:17:16 +00:00
scanf("%d", &temp[0]);
2021-10-29 08:51:54 +00:00
printf("插入秩为%d处\n",v.search(temp[0]) + 1);
(v.insert(v.search(temp[0]) + 1, temp[0]) != -1) ? (printf("输出数组\n")) : (printf("无此元素或超出范围\n"));
2021-10-08 09:17:16 +00:00
v.printall();
break;
case 2:
2021-10-29 08:51:54 +00:00
printf("输入待删除元素\n");
2021-10-08 09:17:16 +00:00
scanf("%d", &temp[0]);
2021-10-29 08:51:54 +00:00
(v.remove_sorted(temp[0]) != -1) ? (printf("输出数组\n")) : (printf("无此元素或超出范围\n"));
2021-10-08 09:17:16 +00:00
v.printall();
break;
case 3:
2021-10-29 08:51:54 +00:00
printf("输入统计的数值\n");
2021-10-08 09:17:16 +00:00
scanf("%d", &temp[0]);
temp[1] = v.count(temp[0]);
2021-10-29 08:51:54 +00:00
(temp[1] != -1) ? (printf("一共%d个\n", temp[1])) : (printf("无此元素或超出范围\n"));
2021-10-08 09:17:16 +00:00
break;
2021-10-08 09:26:01 +00:00
case 4:
return 0;
2021-10-15 07:20:32 +00:00
2021-10-08 09:17:16 +00:00
default:
2021-10-29 08:51:54 +00:00
printf("返回菜单\n");
2021-10-08 09:17:16 +00:00
}
flag = 0;
}
2021-10-03 02:28:37 +00:00
return 0;
2021-10-15 07:20:32 +00:00
}