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
2021-12-19 22:25:07 +08:00

59 lines
1.5 KiB
C++

#include <stdio.h>
#include <stdlib.h>
#include "vec.h"
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("排序:秩为%d\n",v.getused());
// v.bubbleSort();
v.mergeSort(0,v.getused());
v.printall();
while (1)
{
printf("选择操作:1.插入 2.删除 3.统计 4.退出\n");
scanf("%d", &flag);
switch (flag)
{
case 1:
printf("输入待插入数值\n");
scanf("%d", &temp[0]);
printf("插入秩为%d处\n",v.search(temp[0]) + 1);
(v.insert(v.search(temp[0]) + 1, 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;
}