• <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)論排行榜

            亚洲国产精品人久久| 久久r热这里有精品视频| 久久久久亚洲AV无码专区网站| 国产成人精品久久| 7777精品伊人久久久大香线蕉| 久久国产欧美日韩精品| 四虎国产永久免费久久| 一本综合久久国产二区| 久久se精品一区精品二区| 欧美成人免费观看久久| 99久久国产综合精品麻豆| 青青草原综合久久大伊人| 欧美一区二区精品久久| 国产成年无码久久久久毛片| 亚洲精品乱码久久久久久不卡| 国产精品99久久久久久人| 伊人久久大香线焦AV综合影院 | 成人久久久观看免费毛片| 一本久久a久久精品综合香蕉| 久久精品国内一区二区三区 | 久久久不卡国产精品一区二区| 久久人人爽人人爽人人片AV不 | 久久婷婷五月综合色奶水99啪| 国产免费福利体检区久久| 狠狠色丁香久久综合婷婷| 久久婷婷国产综合精品| 欧美精品乱码99久久蜜桃| 日本亚洲色大成网站WWW久久 | 无码八A片人妻少妇久久| 久久亚洲精品无码播放| 久久精品国产一区二区电影| 国产精品一区二区久久精品无码 | 色狠狠久久AV五月综合| 久久久国产打桩机| 亚洲综合熟女久久久30p| 无码人妻久久一区二区三区蜜桃 | 国产午夜电影久久| 91精品免费久久久久久久久| 26uuu久久五月天| 国产精品亚洲美女久久久| 亚洲国产香蕉人人爽成AV片久久|