-->
当前位置:首页 > 题库

PROGRAMMING:Simulation Implementation of set (function template)

Luz5年前 (2021-05-10)题库375
We can use an array to simulate a set, add operation to add set elements, delete operation to delete set elements, and find operation to find set elements. However, the type of set elements is unknown, which can be basic data types such as int, char and double, or object types such as string, time and student, Template functions are required to add, delete and search the set elements.
The three template functions are as follows:
int addSet(T * myset, T elem,int len)
int deleSet(T * myset, T elem, int len)
int findElem(T * myset, T elem, int len)
Among them, addset adds an element to the collection, deleset removes an element from the collection, findelement judges whether element is a member of the collection, and three functions return the insertion position, deletion position and existence position of the element respectively.
The main function has the following data members:
int intSet[100]
double douSet[100]
String strset [100] is an array collection of int type, double type and string.
Int, intlen, doulen and strlen are the lengths of array sets of int type, double type and string respectively
According to the input information, the main function establishes the initial empty set, calls three template functions to perform corresponding operations on intset, douset and strset, and outputs the corresponding set information.
Input format:
Each line has a set operation. The first number of each line is set element type, 1 is integer element, 2 is floating point element, 3 is string type. The second number is set operation type, 1 is insert, 2 is delete, 3 is search, and the third is set element. The set element type depends on the set element type given by the first number. Enter 0 to mark the end of input.
Output format:
Output the execution position (insert position, delete position and exist position) of the current operation
When deleting, if element X does not exist, output "x is not exist!".
When inserting, if the set is full, output "full set." if the element already exists, output "x is already exist!"
If the element cannot be found in the lookup operation, the output "x is not exist!".
Input:
1 1 1
1 1 2
1 3 1
1 2 1
1 2 3
1 3 1
2 1 1.1
2 1 2.2
2 1 3.3
2 3 1.1
2 2 2.2
2 2 2.2
3 1 abc
3 1 bcd
3 3 abc
3 2 abc
3 3 abc
0
Output:
0
one
0
0
3 is not exist!
1 is not exist!
0
one
two
0
one
2.2 is not exist!
0
one
0
0
abc is not exist!< br>





answer:If there is no answer, please comment