1. Why is a template class used in C ++? (1) It can be used to create a data structure with dynamic growth and reduction. (2) It is type-independent and therefore highly reusable. (3) It checks the data type during compilation rather than during runtime, ensuring the type security. (4) It is platform-independent and portable. (5) It can be used for basic data types. 2. return function value, input x = 9999; int func (x) {int countx = 0; while (x) {countx ++; x = x & (x-1 );} return countx;} What is the result? Knowing how many 1 functions are included in the binary value of 9999, and the number of 1 contained in 9999 = 9x1024 + 512 + 256 + 15 9x1024 is 2; 512 contains 1 of 1, 256 contains 1 of 1, 15 contains 1 of 4, so the total number of 1 is 8, and the result is 8. 1000-1 = 0111, which is the inverse of the original number. This is the principle. Using this method to calculate the number of 1 is very efficient. You do not have to shift one by one. The minimum number of cycles. 3. What is the difference between overload and override of C ++? Features of a member function that is overloaded: (1) the same range (in the same class); (2) the same function name; (3) Different parameters; (4) the virtual keyword is dispensable. Rewriting refers to the function of the derived class to override the base class function. It represents the polymorphism of C ++ and has the following characteristics: (1) different ranges (located in the derived class and the base class respectively); (2) function names are the same; (3) parameters are the same; (4) Base-class functions must have virtual keywords. 4. What is the difference between SendMessage and PostMessage in MFC? The difference between PostMessage and SendMessage is whether to wait for the application to process the message. PostMessage only puts the message into the queue and continues execution. The SendMessage must wait for the application to process the message before returning the message to continue execution. The returned values of these two functions are also different. The returned values of PostMessage indicate whether the execution of the PostMessage function is correct, and the returned values of SendMessage indicate the returned values after other programs process messages. 5. programming (Mandatory) Linked lista. implement a linked list forintegers, which supports the insertafter (insert a node after a specified node) and removeafter (remove the node after a specified node) methods; B. implement a method to sort the specified list to descending order. a: The question refers to the implementation of an integer linked list that supports insert and delete operations (with special requirements, all operations are performed after the specified node ), and write a method to sort the Linked List data in descending order. Then we may wish to program with a linear linked list. // The structure of a single-chain table is typedef struct LNode {int data; struct LNode * next;} LNode, * pLinkList; // class LinkList {private: pLinkList m_pList; int m_listLength; public: LinkList ();~ LinkList (); bool InsertAfter (int afternode, int data); // insert bool RemoveAfter (int removenode); // Delete void sort (); // sort }; implementation Method // insert a node after a specified nodebool LinkList: InsertAfter (int afternode, int data) {LNode * pTemp = m_pList; int curPos =-1; if (afternode> m_listLength) // the insertion point exceeds the total length {return false;} while (pTemp! = NULL) // find the specified node {curPos ++; if (curPos = afternode) break; pTemp = pTemp-> next;} if (curPos! = Afternode) // The node is not found, and the error exits {return false;} LNode * newNode = new LNode; // inserts the new node into the specified node and then newNode-> data = data; newNode-> next = pTemp-> next; pTemp-> next = newNode; m_listLength ++; return true ;}// remove the node after a specified nodebool LinkList :: removeAfter (int removenode) {LNode * pTemp = m_pList; int curPos =-1; if (removenode> m_listLength) // The deletion point exceeds the total length {return false ;} // find the last node of the specified node, because the last node is deleted while (pTemp! = NULL) {curPos ++; if (curPos = removenode + 1) break; pTemp = pTemp-> next;} if (curPos! = Removenode) // The node is not found, and the error exits {return false;} LNode * pDel = NULL; // Delete the node pDel = pTemp-> next; pTemp-> next = pDel-> next; delete pDel; m_listLength-; return true;} // sort the linked list to descending order. void LinkList: sort () {if (m_listLength <= 1) {return;} LNode * pTemp = m_pList; int temp; // sort by method of selection for (int I = 0; I <M_LISTLENGTH-1; I ++) for (int j = I + 1; j <M_LISTLENGTH; J ++) if (pTemp [I]. data <PTEMP [J]. DATA) {temp = pTemp [I]. d Ata; pTemp [I]. data = pTemp [j]. data; pTemp [j]. data = temp ;}} the first two functions implement requirements a, and the last function sort () implements requirements B 6. what is the portal for Windows programs? Write the Windows Message Mechanism process. Windows program entry is the WinMain Function Message mechanism: the system will maintain one or more message queues, all generated messages will be put or inserted into the queue. The system extracts each message from the queue and sends the message to the program with the window according to the message receiving handle. Each running program has its own message loop. in the loop, it obtains its own message and calls the corresponding window process according to the handle of the receiving window. When there is no message, the message loop gives control to the system. 7. How to define and implement a class member function as a callback function? The so-called callback function registers the function in advance to let the system know the existence of the function. In the future, when an event occurs, the system calls this function to respond to the event. When defining a member function of a class, add CALLBACK before the function to define it as a CALLBACK function. The implementation of the function is no different from that of a common member function. 8. What are the implementation principles of vswitches and vrouters? At which level is the implementation implemented? The switch belongs to the second layer of OSI, that is, the data link layer device. It selects routes from the station table based on MAC address addressing. The establishment and maintenance of the station table is automatically implemented by the switch. A router is a layer-3 network-layer device of OSI. It is addressing based on IP addresses and is generated through the route table routing protocol. The biggest advantage of a vswitch is its speed. The biggest advantage of a vro is its strong control capability. 9. What is the difference between global variables and local variables? How is it implemented? How does the operating system and compiler know? Some variables are visible throughout the program. They are called global variables. Some variables can only be known in one function, called Local variables. This is their difference. Variables defined outside any function are global variables, and variables defined inside the function are local variables, which are their implementation processes in the program. The operating system and compiler know them according to the memory area where the program runs. The global data of the program is stored in the global data area of the allocated memory, and the local data of the program is stored in the stack area. 10. C ++: What is the fundamental difference between memset, memcpy, and strcpy? # Include "memory. h "memset is used to set all memory spaces to a specific character. It is generally used to initialize the defined string to'' or '\ 0'. For example, char a [100]. memset (a, '\ 0', sizeof (a); memcpy is used for memory copying. You can use it to copy any data type object and specify the length of the copied data. For example: char a [100], B [50]; memcpy (B, a, sizeof (B); note that if sizeof (a) is used, the memory address of B may overflow. Strcpy can only copy strings. It ends copying when '\ 0' is encountered. For example, chara [100], B [50]; strcpy (a, B ); for example, if strcpy (B, a) is used, check whether the string length (before the first '\ 0') in a exceeds 50 bits. If it exceeds, this will cause memory address overflow of B. 11. What is ASSERT ()? ASSERT () is a macro that is often used when debugging a program. When the program is running, it calculates the expressions in parentheses. If the expression is FALSE (0), the program reports an error and terminates the execution. If the expression is not 0, execute the following statement. This macro often used to determine whether the program contains clearly illegal data. If the program is terminated, it will not cause serious consequences, but also facilitate searching for errors. 12. Binary Search Algorithm Implementation. 1. Recursive Method implementation: int BSearch (elemtype a [], elemtype x, intlow, int high)/* at the next session is low, if (low> high) return-1; mid = (low + high)/2; x */{int mid; if (x = a [mid]) return mid; if (x <a [mid]) return (BSearch (a, x, low, mid-1 )); else return (BSearch (a, x, mid + 1, high);} 2. Non-recursive method implementation: int BSearch (elemtype a [], keytype key, int n) {int low, high, mid; low = 0; high = n-1; while (low <= high) {mid = (low + high)/2; if (a [mid]. key = key) return mid; else if (a [mid]. key <key) low = mid + 1; else high = mid-1;} return-1 ;}