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/ex3/ex3.cpp
2021-10-08 17:26:01 +08:00

57 lines
No EOL
1.3 KiB
C++

#include <stdio.h>
#include <stdlib.h>
#include "vec.cpp"
int main()
{
int flag = 0;
int temp[5];
srand(time(NULL));
int len;
printf("输入生成数量\n");
scanf("%d", &len);
Vec v(len);
v.printall();
system("pause");
printf("排序\n");
v.sort();
v.printall();
while (1)
{
printf("选择操作:1.插入 2.删除 3.统计 4.退出\n");
scanf("%d", &flag);
switch (flag)
{
case 1:
printf("输入待插入数值\n");
scanf("%d", &temp[0]);
(v.insert(v.search(temp[0]), temp[0]) != -1) ? (printf("输出数组\n")) : (printf("无此元素或超出范围\n"));
v.printall();
break;
case 2:
printf("输入待删除元素\n");
scanf("%d", &temp[0]);
(v.remove_sorted(temp[0]) != -1) ? (printf("输出数组\n")) : (printf("无此元素或超出范围\n"));
v.printall();
break;
case 3:
printf("输入统计的数值\n");
scanf("%d", &temp[0]);
temp[1] = v.count(temp[0]);
(temp[1] != -1) ? (printf("一共%d个\n", temp[1])) : (printf("无此元素或超出范围\n"));
break;
case 4:
return 0;
default:
printf("返回菜单\n");
}
flag = 0;
}
return 0;
}