From: http://blog.csdn.net/feixiaoxing/article/details/6802182
Generic programming is not difficult. In essence, generic programming is the application of universal algorithms to all data types. Specifically, int is the type of integer we are familiar with. So in general, if we write an int integer sorting algorithm, how should we write it. We can try it by ourselves. The following code is an example of me; view plain Void bubble_sort (int array[], int length) { int temp = 0; int outer = 0; int inner = 0; ASSERT (Null != array && 0 != length); for (outer = length -1; outer >= 1; outer --) { for (inner = 0; inner <= outer; inner ++) { if (array[inner] >&NBSP;ARRAY[INNER&NBSP;+&NBSP;1]) { temp = array[inner]; array[inner] = array[inner + 1]; array[inner + 1] = temp; } } } return; } If you change the data type to a generic data type, what do you need to do? Two: (1) The arithmetic character "=" overload, (2) the comparison function. The following is the class type of a design.
View Plain class Type {