C + + (generics programming) from the perspective of Assembly

Source: Internet
Author: User

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 {

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.