• <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>

            JonsenElizee

            Software Developing Blog

            "An idea is fragile . It can be killed by a scornful smile or a yawn .It can be mound down by irony and scared to death by a cold look."
            "Most cultures throughout human history have not liked creative individuals .They ignore them or kill them.It is a very efficient way of stopping creativity."

            ------Advertising boss Charles Browe and Howard Gardner ,professor at Harvard

               :: 首頁 :: 新隨筆 ::  ::  :: 管理 ::

            Refer Find kth number in O(n) TC

            #
            include <stdio.h>
            #include <stdlib.h>
            #include <time.h>

            #define N 20

            void init_a(int A[])
            {
              int i = 0;
              for(;i<N;i++)
                A[i] = rand()%100;
            }

            void print_array(int A[])
            {
               int i = 0;
               for(;i<N;i++)
                {
                 if(i==9)
                  printf("%d\n",A[i]);
                 else
                  printf("%d\t",A[i]);
                }
            }

            void swap(int* a, int* b)
            {
               int tmp = *a;
               *a = *b;
               *b = tmp;
            }

            int rand_partition(int A[], int start, int end)
            {
               int i = start-1;
               int j = start;
               int num = rand()%(end-start+1)+start;
               swap(A+num,A+end);
               int x = A[end];
               
               for(;j<end;j++)
                {
                  if(A[j]<=x)
                   {
                      i++;
                     swap(A+i,A+j);
                    }
                 }
               swap(A+i+1,A+end);

               return i+1;
            }


            int random_select(int A[], int start, int end, int k)
            {
              int i = 0;
              if(start == end)
                return A[start];
                
              int q = rand_partition(A, start, end);
               i = q-start+1;
              
              if(i == k)
                return A[q];
              else if(i<k)
                return random_select( A, q+1, end, k-i);
              else
                return random_select( A, start, q-1, k);
            }

            void quick_sort(int A[], int start, int end)
            {
              if(start<end)
               {
                 int q = rand_partition(A, start, end);
              
                  quick_sort( A, q+1, end);
                  quick_sort( A, start, q-1);
              }
            }
               
            int main(int argc, char *argv[])
            {
              int A[N];
              int num = 0;
              int res = 0;
              srand((unsigned)time(NULL));
               init_a(A);
               print_array(A);
              
               num = rand()%(N-10)+5;
              printf("we begin select %d minimun number\n",num);
               res = random_select( A, 0 , N-1, num);
              printf("and num is %d\n",res);
              
               quick_sort( A, 0 , N-1);
              printf("after quick sort the array is:\n");
               print_array(A);
              system("PAUSE");    
              return 0;
            }
            posted on 2010-10-24 01:17 JonsenElizee 閱讀(427) 評論(0)  編輯 收藏 引用 所屬分類: Data Structures & Algorithms
            By JonsenElizee
            AV狠狠色丁香婷婷综合久久| 欧美激情精品久久久久| 一本大道久久香蕉成人网| 少妇人妻综合久久中文字幕| 亚洲色大成网站WWW久久九九| 99精品久久久久中文字幕| 精品人妻伦九区久久AAA片69| 99久久香蕉国产线看观香| av无码久久久久久不卡网站| 国内精品久久久久久不卡影院| 国内精品人妻无码久久久影院导航| 亚洲色大成网站WWW久久九九| 国产三级观看久久| 久久水蜜桃亚洲av无码精品麻豆| 国产精品免费久久| 国产成人精品综合久久久久| 伊人热人久久中文字幕| 久久国产精品无码HDAV| 性做久久久久久久久浪潮| 精品久久久久久国产三级| 精品综合久久久久久888蜜芽| 久久精品国产99国产精品亚洲| 色综合合久久天天给综看| 观看 国产综合久久久久鬼色 欧美 亚洲 一区二区 | 久久国产香蕉一区精品| 久久99国产综合精品女同| 久久妇女高潮几次MBA| 久久综合伊人77777| 久久99精品九九九久久婷婷| 天天久久狠狠色综合| 久久九九亚洲精品| 麻豆精品久久精品色综合| 久久国产精品-国产精品| 国产精品99久久免费观看| 天堂久久天堂AV色综合| 亚洲精品乱码久久久久久蜜桃不卡 | 亚洲国产精品18久久久久久| 中文字幕无码精品亚洲资源网久久 | 婷婷五月深深久久精品| 热re99久久6国产精品免费| 久久夜色精品国产噜噜亚洲AV|