1321 solid foundation: the programming language, data structures and algorithms

Programming language:

Q: If you write a function need to pass a pointer, you need to add const for pointers? Is there a difference plus the const pointer in a different location?

A: const is used to declare a constant, if you do not want to change a value should be added const. First look at the following piece of code:

    int a = 100;
    const int *b = &a;        // 1
    int const *b = &a;        // 2
    int  *const b = &a;        // 3
    const int *const b = &a;        // 4

  One way to distinguish constant pointers and pointer constant is looking const is left or right of the asterisk. If it is in the form of 1 and 2 is a constant pointer (a pointer to a constant content), as independent variables in the const specifier position, it is equivalent to 1 and 2, this form * b can not be changed, but can b variable, i.e., a pointer to the content can not be changed, but a pointer can change. If 3 is in the form of the pointer it is constant (constant pointer originally), which can change form * b, b but can not be changed, i.e., the content pointer can be changed, but a pointer can not be changed.

Q: If you need to write a function argument passed is an example of a complex type, the value and pass by reference pass What is the difference? When should pass a reference to add const?
A: There are three cases.

1. const modifier function parameters passed

  For example non-intra data type, such as a class of complex, should pass the value to pass by reference, the aim of reducing the copy (e.g. copy constructor calls), to improve efficiency. But for internal data types, such as int, you can not pass value to pass by reference, otherwise not only can not improve efficiency, but reduce the readability of the code.

2 modified with the function return value const

  If the pointer type manner as a function return value, const added, represents the function returns a value (pointer) content can not be modified, and can only be assigned to the same type const qualifier pointer. Of course, you can go with const_cast const electrical properties. If the value type as the return value of a function of the way, since the return value is copied into a temporary variable, so that no use const added. If the reference type manner as a function return value, plus const not usually the case, but it must be added at the time const overload class assignment number, the purpose of chain expression.

3. const member functions modified

  In order to improve the robustness of the code, it does not modify any data members of the member functions should be modified to const, and const to pay attention behind the increase in the parameter list.

Data structures:
1. master data structure of linked lists, trees, stacks, queues, hash tables, and the like, and related operations?
A:
2. How to insert and delete nodes linked list to write?
A:
In the tree traversal 3. 6 how to write?
answer:

Algorithm:
1. Understand the various search and sort algorithms and principles of time and space complexity and so on?
A:
2. Key master binary search, binary sort tree to find?
A:
3. master key insertion sort, bubble sort, merge sort, quick sort?
A:
4. understand the principles of dynamic programming and greedy algorithms?
answer:

Guess you like

Origin www.cnblogs.com/parzulpan/p/11247375.html