• <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久久免费只有精品国产| 人人狠狠综合久久亚洲高清| 香蕉99久久国产综合精品宅男自 | 欧美性大战久久久久久| 99久久夜色精品国产网站| 国产免费久久精品99久久| 亚洲精品97久久中文字幕无码| 久久久久亚洲AV片无码下载蜜桃| 久久精品国产亚洲av影院| 久久免费大片| 一本色道久久88精品综合| 久久久免费观成人影院 | 国产色综合久久无码有码| 无码专区久久综合久中文字幕 | 久久天天躁狠狠躁夜夜2020| 热久久国产欧美一区二区精品| 天天爽天天狠久久久综合麻豆| 久久久久99精品成人片三人毛片| 久久午夜羞羞影院免费观看| 亚洲国产精品综合久久一线| 91精品国产色综合久久| AV无码久久久久不卡蜜桃| 久久久久久无码国产精品中文字幕| 久久久噜噜噜久久熟女AA片| 久久久久久曰本AV免费免费| 久久久久亚洲精品中文字幕| 狠狠精品干练久久久无码中文字幕 | 国产高潮久久免费观看| 久久久久国产精品麻豆AR影院 | 99久久99久久精品免费看蜜桃 | 久久99国产精品成人欧美| 久久久国产精华液| 伊人热热久久原色播放www| 国产精品免费久久久久影院| 国产激情久久久久影院老熟女免费| a级成人毛片久久| 久久国产精品无码一区二区三区| 久久久久AV综合网成人|