• <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) 評(píng)論(0)  編輯 收藏 引用 所屬分類(lèi): C++ problem and solution

            My Links

            Blog Stats

            News

            常用鏈接

            留言簿(1)

            隨筆分類(lèi)(13)

            隨筆檔案(17)

            文章檔案(1)

            相冊(cè)

            收藏夾(1)

            Friends' blog

            useful sites

            搜索

            積分與排名

            最新評(píng)論

            閱讀排行榜

            評(píng)論排行榜

            精品国产99久久久久久麻豆| 欧美一区二区精品久久| 亚洲中文字幕无码久久精品1| 亚洲精品午夜国产va久久| 日本人妻丰满熟妇久久久久久| 久久国产色AV免费看| 国产免费久久精品丫丫| 日产精品久久久久久久| 久久99精品国产麻豆不卡| 久久亚洲精品成人AV| 久久99久久无码毛片一区二区 | 免费精品久久久久久中文字幕| 99精品久久精品一区二区| 成人国内精品久久久久影院VR| 久久天天躁狠狠躁夜夜不卡| 一本一道久久精品综合| 97精品依人久久久大香线蕉97| 久久99精品久久久久久齐齐| 91精品国产色综合久久| 亚洲国产精品成人久久蜜臀 | 思思久久99热只有频精品66| 精品无码久久久久国产| 麻豆av久久av盛宴av| 亚洲人成无码www久久久| 亚洲狠狠综合久久| 91精品国产91久久综合| 亚洲精品tv久久久久久久久| 久久狠狠一本精品综合网| 国产成人精品久久亚洲高清不卡 | 久久AV高清无码| 2021少妇久久久久久久久久| 97久久国产露脸精品国产| 中文字幕乱码久久午夜| 久久精品一本到99热免费| 久久久精品国产| 久久AV高潮AV无码AV| 伊人久久综合成人网| 狠狠色婷婷久久综合频道日韩| 久久久久久精品免费免费自慰| 国内精品久久久久影院薰衣草| 久久精品国产亚洲AV忘忧草18|