Lab 08 - C Preprocessor
Last updated
Last updated
Slides:
will include the \n
character.
Use #define
to define a constant to make your program more readable.
A macro is a code snippet that is substituted into the program and expanded during pre-processing.
Example:
We can use a generic type (or type parameter) to restrict the type of the arguments used in a macro.
Example:
Be careful with situations like this:
Therefore, we should always use brackets around the arguments of a macro, i.e., SQUARE(x) (x) * (x)
is safe.
There are five major types of operations which are core to algorithm optimization: insertion, removal, retrieval, searching and sorting.
Probably the most powerful search algorithm for simple arrays.
The idea of search space.
Sorted means non-descending in CS.
The idea is the pair-wised comparison is important.
To use it on negative indices, use the idea of mapping. For example, -9 to 0.
Start from the minimum point, have two directions.
There are some better cases when the time complexity is .
When the array is sorted, the time complexity is
The time complexity is always
Every time see , try thinking about binary search.
Every time see , which means can done in one iteration.