• <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)  編輯 收藏 引用 所屬分類: C++ problem and solution

            My Links

            Blog Stats

            News

            常用鏈接

            留言簿(1)

            隨筆分類(13)

            隨筆檔案(17)

            文章檔案(1)

            相冊(cè)

            收藏夾(1)

            Friends' blog

            useful sites

            搜索

            積分與排名

            最新評(píng)論

            閱讀排行榜

            評(píng)論排行榜

            国产精品99精品久久免费| 亚洲乱码日产精品a级毛片久久| 久久久91人妻无码精品蜜桃HD| 精品人妻伦九区久久AAA片69| 国色天香久久久久久久小说 | 午夜精品久久久久9999高清| 精品久久8x国产免费观看| 91精品国产色综久久| 欧洲精品久久久av无码电影| 性高湖久久久久久久久AAAAA| 国产亚洲精久久久久久无码77777| 996久久国产精品线观看| 久久久久久久97| 国产精品久久久久蜜芽| 日本精品久久久久影院日本| 久久久久久亚洲AV无码专区| 久久综合噜噜激激的五月天| 久久精品国产99久久丝袜| 精品熟女少妇av免费久久| 久久久久久久综合综合狠狠| 久久不射电影网| 99久久无码一区人妻| 无码人妻少妇久久中文字幕蜜桃| 精品视频久久久久| 国产成年无码久久久久毛片| 国产毛片欧美毛片久久久| 久久精品一区二区影院| 久久99国产亚洲高清观看首页| A级毛片无码久久精品免费 | 丰满少妇高潮惨叫久久久| 一本久久综合亚洲鲁鲁五月天亚洲欧美一区二区 | 人妻少妇精品久久| 久久久久久久综合日本| 久久午夜无码鲁丝片午夜精品| 亚洲国产精品成人久久蜜臀| 大蕉久久伊人中文字幕| 久久久久久国产a免费观看黄色大片 | 久久亚洲私人国产精品vA | 久久久久av无码免费网| 四虎亚洲国产成人久久精品| 人妻丰满?V无码久久不卡|