• <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 丑石 閱讀(331) 評論(0)  編輯 收藏 引用 所屬分類: C++ problem and solution

            My Links

            Blog Stats

            News

            常用鏈接

            留言簿(1)

            隨筆分類(13)

            隨筆檔案(17)

            文章檔案(1)

            相冊

            收藏夾(1)

            Friends' blog

            useful sites

            搜索

            積分與排名

            最新評論

            閱讀排行榜

            評論排行榜

            久久青青草原精品国产软件| 欧美日韩精品久久久免费观看| 国产精品亚洲综合久久| 一本大道久久东京热无码AV | 久久99精品久久久久久齐齐| 久久无码精品一区二区三区| 久久中文字幕人妻熟av女| 久久精品www人人爽人人| 国产成人精品久久二区二区| 久久精品成人免费国产片小草| 久久亚洲日韩看片无码| 国产2021久久精品| 日本强好片久久久久久AAA| 成人精品一区二区久久久| 久久九九久精品国产免费直播| 青青青国产精品国产精品久久久久| 亚洲欧洲久久久精品| 久久精品国产影库免费看| 精品国产乱码久久久久久呢| 精品久久人人做人人爽综合| 久久久久亚洲AV片无码下载蜜桃| 亚洲精品97久久中文字幕无码| 亚洲成人精品久久| 中文字幕亚洲综合久久菠萝蜜| 亚洲AV无码久久精品成人| 日本久久中文字幕| 国产精品免费久久久久影院 | 久久这里只有精品视频99| 久久综合狠狠综合久久综合88| 青青草国产97免久久费观看| 久久精品国产精品亚洲精品| 国产精品久久成人影院| 久久国产精品无码HDAV | 久久久久婷婷| 国产精品嫩草影院久久| 亚洲精品高清久久| 94久久国产乱子伦精品免费| 久久99精品国产麻豆宅宅| WWW婷婷AV久久久影片| 精品久久久久久无码专区| 久久久久免费精品国产|