[Huawei machine trial exercise questions] 57. Object Manager, Huawei exercise questions

Source: Internet
Author: User

[Huawei machine trial exercise questions] 57. Object Manager, Huawei exercise questions

Question

Code

/* ------------------------------------- * Date: 2015-07-05 * Author: SJF0115 * Subject: Object Manager * Source: Huawei machine trial exercises */# include <iostream> # include "ObjMgt. h "# include <vector> using namespace std; struct Object {unsigned int key1; unsigned int key2; unsigned int key3; Object (unsigned int a, unsigned int B, unsigned int c) {key1 = a; key2 = B; key3 = c;} Object () {}}; vector <Object> containe R;/* Add function: add a single object input: key1 external keyword KEY1 key2 external keyword KEY2key3 external keyword KEY3 output: No Return:-1: Failed (the object already exists or has other exceptions) 0: Success */int AddObject (unsigned int key1, unsigned int key2, unsigned int key3) {int isExits = IsObjectExist (key1, key2, key3 ); // The object already exists if (isExits) {return -1;} // if Object o (key1, key2, key3); container. push_back (o); return 0;}/* deletion function: delete one or more objects input: key1 external keyword KEY1 key2 external keyword KEY2 key3 external keyword KEY3 output: no return: note: The Use Case ensures that the parameter values are valid and the wildcard 0 xFFFFFFFF, And the wildcard represents 0 ~ Any value in the range of 65535. For example: key1 = 1, key2 = 2, key3 = 0 xffffff, indicating to delete all objects of key1 = 1, key2 = 2; key1, key2, when key3 is set to 0xFFFFFFFF, all objects are deleted. Optional */void DeleteObject (unsigned int key1, unsigned int key2, unsigned int key3) {Object o; vector <Object >:: iterator ite = container. begin (); while (ite! = Container. end () {o = * ite; if (o. key1 = key1 | key1 = 0 xFFFFFFFF) & (o. key2 = key2 | key2 = 0 xFFFFFFFF) & (o. key3 = key3 | key3 = 0 xFFFFFFFF) {ite = container. erase (ite) ;}// if else {++ ite ;}// else} // while return ;}/ * exist function: query whether a single object has input: key1 external keyword KEY1 key2 external keyword KEY2 key3 external keyword KEY3 output: No Return: 0: No exist 1: exist else */int IsObjectExist (unsigned int key1, unsigned int key2, unsigned int key3) {int size = container. size (); Object o; for (int I = 0; I <size; ++ I) {o = container [I]; if (o. key1 = key1 & o. key2 = key2 & o. key3 = key3) {return 1;} // if} // for return 0;}/* define Description clears all objects Prototype void Clear (); input Param no Output Param no Return Value no completion */void Clear (void) {container. clear (); return ;}

Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.