• <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

            搜索

            積分與排名

            最新評論

            閱讀排行榜

            評論排行榜

            99久久精品午夜一区二区| 国产精品18久久久久久vr| 国产—久久香蕉国产线看观看| 久久精品国产亚洲AV麻豆网站| 国产精品久久久亚洲| 国产午夜精品久久久久九九| 久久综合色之久久综合| 亚洲精品无码久久久久久| 亚洲国产成人久久精品影视| 欧美亚洲色综久久精品国产| 国产精品久久永久免费| 色婷婷狠狠久久综合五月| 老色鬼久久亚洲AV综合| 精品久久久久久久久久久久久久久| 久久国产AVJUST麻豆| 国产韩国精品一区二区三区久久| 青青草原综合久久大伊人导航| 久久狠狠高潮亚洲精品| 日产久久强奸免费的看| 色综合久久精品中文字幕首页| 亚洲AV成人无码久久精品老人| 久久国产成人午夜AV影院| 精品免费久久久久久久| 国产精品久久久久久久久久影院| 国产精品天天影视久久综合网| 欧美精品国产综合久久| 久久99国产精品成人欧美| 色综合久久最新中文字幕| 日产精品99久久久久久| 亚洲愉拍99热成人精品热久久 | 久久国产免费直播| 色婷婷久久久SWAG精品| 精品欧美一区二区三区久久久| 久久人人爽人人爽人人AV| 久久精品国产亚洲αv忘忧草| 久久婷婷五月综合色99啪ak| 94久久国产乱子伦精品免费 | 久久午夜无码鲁丝片午夜精品| 91麻豆精品国产91久久久久久| 久久国产热精品波多野结衣AV| 久久99精品久久久久久久不卡|