• <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精品国产麻豆不卡| 久久无码中文字幕东京热| 国产亚洲综合久久系列| 久久被窝电影亚洲爽爽爽| 久久久WWW成人免费精品| 午夜久久久久久禁播电影| 爱做久久久久久| 国产精品亚洲综合久久| 久久这里只有精品久久| 久久99精品国产麻豆宅宅| 狠狠久久综合伊人不卡| 色婷婷综合久久久久中文一区二区| 久久精品国产只有精品2020| 久久久国产亚洲精品| 99国内精品久久久久久久| 久久久久波多野结衣高潮| 久久久久久一区国产精品| 国产成年无码久久久久毛片| 97久久国产露脸精品国产| 理论片午午伦夜理片久久| 日韩一区二区久久久久久| 久久不见久久见免费视频7| 久久人人添人人爽添人人片牛牛| 久久九九久精品国产| 日韩欧美亚洲综合久久影院d3| 97久久超碰国产精品2021| 少妇久久久久久久久久| 久久精品国产久精国产果冻传媒| 欧美久久综合九色综合| 久久久精品国产亚洲成人满18免费网站| 久久亚洲精品中文字幕| 亚洲中文字幕无码久久2017| 亚洲国产精品成人久久蜜臀 | 欧美激情精品久久久久久久| 欧美久久综合性欧美|