• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            linux&c++ R&D

            programing is a pleasure!

            separate-array-of-pointers technique

            what is separate-array-of-pointers technique? when and where can it be used?
            here I will explain it.
            separate-array-of-pointers is a array of pointers each of which points at one element of another array.when we sort a array  whose elements may be a large structure,it may be useful. As the array is sorted ,it will spend much time. Beause a lot of data will be copied back and forth.we can exploite separate-array-of-pointers technique.

            /*
            * demonstrate the use of separate-array-of-pointers technique.
            *  
            */

            #include 
            <stdio.h>
            #include 
            <stdlib.h>

            struct employee
            {
                   
            char name[20];
                   
            long emp_id;
                   }
            ;
            int emp_pointer_name_compare(const void *e1p,const void *e2p)
            {
              
            const struct employee **e1,**e2;
              e1
            =(const struct employee* *) (e1p); //it is hard to understand?
              e2=(const struct employee* *) (e2p);
              
            return strcmp((*e1)->name,(*e2)->name);
                 
                  
            }

            /*
            int emp_name_compare(const void *e1p,const void * e2p)
            {
              const struct employee *e1,*e2;
              e1=(const struct employee* ) (e1p); //it is hard to understand?
              e2=(const struct employee* ) (e2p);
              return strcmp(e1->name,e2->name);
            }
            */

            int main()
            {
            struct employee employees[
            10];
            struct employee 
            *pemployees[10];
            char buf[BUFSIZ];
            int i,nep;
            for(nep=0;nep<3 &&fgets(buf,BUFSIZ,stdin)!=NULL;nep++)
            {
                         sscanf(buf,
            "%s %ld\n",&employees[nep].name,
                                               
            &employees[nep].emp_id);
                         pemployees[nep]
            =&employees[nep];                     
                                               
            }
               
            qsort(pemployees,nep,sizeof(struct employee 
            *),emp_pointer_name_compare);

            /*qsort(employees,nep,sizeof(struct employee),emp__name_compare);*/

            printf(
            "Sorted by name:");
            for(i=0;i<nep;i++)
            {
             printf(
            "%s %ld \n",pemployees[i]->name,pemployees[i]->emp_id);
            }
             
            scanf(
            "%d",&i);
            return 0;    
            }





              

            posted on 2007-05-30 18:45 丑石 閱讀(334) 評論(0)  編輯 收藏 引用 所屬分類: C++ problem and solution

            My Links

            Blog Stats

            News

            常用鏈接

            留言簿(1)

            隨筆分類(13)

            隨筆檔案(17)

            文章檔案(1)

            相冊

            收藏夾(1)

            Friends' blog

            useful sites

            搜索

            積分與排名

            最新評論

            閱讀排行榜

            評論排行榜

            人妻无码久久一区二区三区免费| 天堂无码久久综合东京热| 久久青青国产| 色偷偷88欧美精品久久久| 无码八A片人妻少妇久久| 久久免费看黄a级毛片| 久久亚洲国产欧洲精品一| 国产精品美女久久久久av爽| 午夜精品久久久内射近拍高清 | 亚洲人成无码www久久久| 中文无码久久精品| 久久婷婷五月综合97色直播| 亚洲欧美成人久久综合中文网| 国产精品久久久久影视不卡| 日韩人妻无码一区二区三区久久99 | 久久久噜噜噜久久熟女AA片| 久久久这里有精品中文字幕| 亚洲精品无码久久一线| 色综合久久88色综合天天 | 久久国产色av免费看| 狠狠色综合久久久久尤物| 精品久久久久久无码中文字幕| 久久综合88熟人妻| 伊色综合久久之综合久久| 国产一久久香蕉国产线看观看| 精品午夜久久福利大片| 久久九色综合九色99伊人| 97久久精品人人做人人爽| 久久最近最新中文字幕大全| 亚洲中文字幕无码久久精品1| 久久婷婷色香五月综合激情 | 国内精品久久久久久久久电影网| 国产AV影片久久久久久| 无码人妻久久一区二区三区免费| 狠狠精品久久久无码中文字幕| 亚洲乱亚洲乱淫久久| 久久精品国产亚洲AV忘忧草18| 久久久久久久久久久| 色欲久久久天天天综合网| 一本色道久久99一综合| 精品一二三区久久aaa片|