• <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 閱讀(418) 評論(0)  編輯 收藏 引用 所屬分類: Data Structures & Algorithms
            By JonsenElizee
            久久久久无码精品国产| 秋霞久久国产精品电影院| 久久综合久久伊人| 久久精品国产亚洲AV蜜臀色欲 | 久久精品中文闷骚内射| 久久久中文字幕| 日日狠狠久久偷偷色综合0| 性欧美丰满熟妇XXXX性久久久| 97久久久久人妻精品专区 | 国产高清美女一级a毛片久久w| 热RE99久久精品国产66热| 久久精品国产亚洲77777| 久久久久国产亚洲AV麻豆| 久久99国内精品自在现线| 热RE99久久精品国产66热| 99久久www免费人成精品| 久久精品夜夜夜夜夜久久| 色悠久久久久久久综合网| 日本一区精品久久久久影院| 久久久久久精品免费免费自慰| 久久www免费人成看国产片| 国产精品美女久久久| 久久夜色精品国产噜噜麻豆| 一极黄色视频久久网站| 久久精品无码av| 久久精品成人欧美大片| 精品免费tv久久久久久久| 少妇人妻88久久中文字幕| 久久久久国产精品人妻| 欧美国产成人久久精品| 青青热久久国产久精品| 深夜久久AAAAA级毛片免费看 | 97久久精品无码一区二区| 亚洲va久久久噜噜噜久久狠狠| 国内精品综合久久久40p| 久久久黄色大片| 国产成人久久精品一区二区三区| 久久婷婷人人澡人人| 亚洲AⅤ优女AV综合久久久| 亚洲日本久久久午夜精品| 婷婷久久综合|