#include #include #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.统计\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; default: printf("返回菜单\n"); } flag = 0; } return 0; }