亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? sort.c

?? 《c語言實例解析精粹》
?? C
?? 第 1 頁 / 共 2 頁
字號:

#include "tdestr.h"
#include "common.h"
#include "tdefunc.h"
#include "define.h"


/*
 * Name:    sort_box_block
 * Purpose: sort lines according to text in marked BOX block
 * Date:    June 5, 1992
 * Passed:  window:  pointer to current window
 * Notes:   quick sort and insertion sort the lines in the BOX buff according
 *           to stuff in a box block.
 */
int  sort_box_block( WINDOW *window )
{
int  prompt_line;
int  block_type;
line_list_ptr ll;
register file_infos *file;
WINDOW *sw;
int  rc;
char line_buff[(MAX_COLS+1)*2]; /* buffer for char and attribute  */

   /*
    * make sure block is marked OK
    */
   rc = OK;
   prompt_line = window->bottom_line;
   entab_linebuff( );
   if (un_copy_line( window->ll, window, TRUE ) == ERROR)
      return( ERROR );
   check_block( );
   if (g_status.marked == TRUE) {
      file  = g_status.marked_file;
      block_type = file->block_type;
      if (block_type == BOX) {
         /*
          * sort ascending or descending?
          */
         rc = get_sort_order( window );
         if (rc != ERROR) {
            file->modified = TRUE;
            if (mode.do_backups == TRUE) {
               sw = g_status.window_list;
               for (; ptoul( sw->file_info ) != ptoul( file );)
                  sw = sw->next;
               backup_file( sw );
            }

            /*
             * figure the width of the block.
             */
            sort.block_len = file->block_ec + 1 - file->block_bc;

            /*
             * save the prompt line and print the quicksort message.
             */
            save_screen_line( 0, prompt_line, line_buff );
            eol_clear( 0, prompt_line, g_display.text_color );
            set_prompt( block22a, prompt_line );

            /*
             * set up the sort structure.
             */
            sort.bc  = g_status.marked_file->block_bc;
            sort.ec  = g_status.marked_file->block_ec;
            sort.order_array = (mode.search_case == IGNORE) ?
                                    sort_order.ignore : sort_order.match;

            /*
             * save the previous node for use with insertion sort.
             */
            ll = file->block_start->prev;
            quick_sort_block( file->block_br, file->block_er,
                              file->block_start, file->block_end );

            /*
             * get back previous node and clean up list with insertion
             *   sort.
             */
            if (ll == NULL)
               ll = file->line_list;
            else
               ll = ll->next;
            set_prompt( block22b, prompt_line );
            insertion_sort_block( file->block_br, file->block_er, ll );

            /*
             * housekeeping.  mark the file as dirty and restore the
             *   cursors, which are scrambled during the sort.
             */
            file->dirty = GLOBAL;
            restore_cursors( file );
            restore_screen_line( 0, prompt_line, line_buff );
         }
      } else {
         /*
          * can only sort box blocks
          */
         error( WARNING, prompt_line, block23 );
         rc = ERROR;
      }
   } else {
      /*
       * box not marked
       */
      error( WARNING, prompt_line, block24 );
      rc = ERROR;
   }
   return( rc );
}


/*
 * Name:    quick_sort_block
 * Purpose: sort lines according to text in marked BOX block
 * Date:    Jaunary 10, 1993
 * Passed:  low:        starting line in box block
 *          high:       ending line in a box block
 *          low_node:   starting node in box block
 *          high_node:  ending node in box block
 * Notes:   Quicksort lines in the BOX block according to keys in
 *           a box block.
 *          because the median of three method is used to find the partion
 *           node,  high - low  should be greater than or equal to 2.
 *          with end recursion removal and sorting the smallest sublist
 *           first, our stack only needs room for log2 (N+1)/(M+2) nodes.
 *           a stack size of 24 can reliably handle almost 500 million lines.
 */
void quick_sort_block( long low, long high, line_list_ptr low_node,
                       line_list_ptr high_node )
{
long low_rline_stack[24];
long high_rline_stack[24];
line_list_ptr low_node_stack[24];
line_list_ptr high_node_stack[24];
long low_count;
long high_count;
long count;
line_list_ptr low_start;
line_list_ptr low_head;
line_list_ptr low_tail;
line_list_ptr high_end;
line_list_ptr high_head;
line_list_ptr high_tail;
line_list_ptr equal_head;
line_list_ptr equal_tail;
line_list_ptr walk_node;
line_list_ptr median_node;
int  i;
int  stack_pointer;

   assert( low_node->len != EOF);
   assert( high_node->len != EOF);

   stack_pointer = 0;
   for (;;) {

      /*
       * being that a median-of-three is used as the partition algorithm,
       *  we probably need to have at least 2 nodes in each sublist.  I
       *  chose a minimum of 25 nodes as a SWAG (scientific wild ass guess).
       *  a simple insertion sort mops the list after quicksort finishes.
       */
      while (high - low > 25) {

         assert( high >= 1 );
         assert( low  >= 1 );
         assert( low  <= high );

         /*
          * start the walk node at the head of the list and walk to the
          *  middle of the sublist.
          */
         walk_node  = low_node;
         count = (high - low) / 2;
         for (; count > 0; count--)
            walk_node = walk_node->next;

         /*
          * now, find the median of the low, middle, and high node.
          *
          * being that I am subject to error, let's assert that we really
          *  did find the median-of-three.
          */
         load_pivot( low_node );
         if (compare_pivot( walk_node ) < 0) {
            low_head   = walk_node;
            median_node = low_node;
         } else {
            low_head   = low_node;
            median_node = walk_node;
         }
         high_head = high_node;
         load_pivot( median_node );
         if (compare_pivot( high_node ) < 0) {
            high_head   = median_node;
            median_node = high_node;
         }
         load_pivot( median_node );
         if (compare_pivot( low_head ) > 0) {
            low_tail    = median_node;
            median_node = low_head;
            low_head    = low_tail;
         }

         load_pivot( median_node );

         assert( compare_pivot( low_head ) <= 0 );
         assert( compare_pivot( high_head ) >= 0 );

         /*
          * now, walk again from the head of the list comparing nodes and
          *  use the first occurrence of the median node as the partition.
          */
         walk_node = low_node;
         for (i = 0; ; walk_node = walk_node->next) {
            if (compare_pivot( walk_node ) == 0)
               break;
            i = 1;
         }

         /*
          * initialize pointers and counters for this partition.
          */
         low_start  = low_node->prev;
         high_end   = high_node->next;
         low_head   = low_tail  = NULL;
         high_head  = high_tail = NULL;
         low_count  = high_count = 0;

         /*
          * setup the first occurrence of the median node as a "fat pivot"
          *  sublist.  there are two cases to consider 1) the first
          *  occurrence of the median node is the first element in the
          *  sublist, i == 0, or 2) the first occurrence of the median node
          *  is somewhere in the sublist.
          */
         if (i == 0)
            walk_node = equal_head = equal_tail = low_node;
         else {
            equal_head = equal_tail = walk_node;
            equal_head->next->prev = equal_head->prev;
            equal_head->prev->next = equal_head->next;
            equal_head->next = low_node;
            walk_node = equal_head;
         }
         load_pivot( equal_head );

         /*
          * PARTITION:
          *  put all nodes less than the pivot on the end of the low list.
          *  put all nodes equal to the pivot on the end of the equal list.
          *  put all nodes greater than the pivot on the end of the high list.
          */
         for (count=low+1; count <= high; count++) {
            walk_node = walk_node->next;
            i = compare_pivot( walk_node );
            if (i > 0) {
               if (high_head == NULL)
                  high_head = high_tail = walk_node;
               else {
                  high_tail->next = walk_node;
                  walk_node->prev = high_tail;
                  high_tail = walk_node;
               }

               /*
                * keep a count of the number of nodes in the high list.
                */
               ++high_count;
            } else if (i < 0) {
               if (low_head == NULL)
                  low_head = low_tail = walk_node;
               else {
                  low_tail->next = walk_node;
                  walk_node->prev = low_tail;
                  low_tail = walk_node;
               }

               /*
                * keep a count of the number of nodes in the low list
                */
               ++low_count;
            } else {
               equal_tail->next = walk_node;
               walk_node->prev = equal_tail;
               equal_tail = walk_node;
            }
         }

         assert( low_count >= 0 );
         assert( low_count < high - low );
         assert( high_count >= 0 );
         assert( high_count < high - low );

         /*
          * we just partitioned the sublist into low, equal, and high
          *  sublists.  now, let's put the lists back together.
          */
         if (low_count > 0) {
            low_head->prev = low_start;
            if (low_start != NULL)
               low_start->next = low_head;
            else
               g_status.marked_file->line_list = low_head;
            low_tail->next = equal_head;
            equal_head->prev = low_tail;
         } else {
            equal_head->prev = low_start;
            if (low_start != NULL)
               low_start->next = equal_head;
            else
               g_status.marked_file->line_list = equal_head;
         }
         if (high_count > 0) {
            high_head->prev = equal_tail;
            equal_tail->next = high_head;
            high_tail->next = high_end;
            high_end->prev  = high_tail;
         } else {
            equal_tail->next = high_end;
            high_end->prev   = equal_tail;
         }

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
国内精品伊人久久久久av一坑| 日韩经典中文字幕一区| 亚洲精品视频一区| 亚洲.国产.中文慕字在线| 久久se精品一区二区| 不卡的电影网站| 91精品在线麻豆| 亚洲欧美影音先锋| 日本成人中文字幕| bt欧美亚洲午夜电影天堂| 欧美性videosxxxxx| 日韩精品一区二区三区视频播放 | 成人性生交大合| 欧洲一区在线观看| 精品久久五月天| 1000精品久久久久久久久| 首页综合国产亚洲丝袜| 成人小视频在线| 日韩欧美在线影院| 一区二区三区欧美日| 国产精品18久久久久久久久| 欧美另类高清zo欧美| 国产精品免费视频观看| 美日韩一区二区| 色综合中文综合网| 中文一区一区三区高中清不卡| 亚洲va欧美va天堂v国产综合| 国产成人一区在线| 在线免费观看成人短视频| 亚洲精品一区二区三区香蕉| 中文字幕一区二区三区不卡在线| 国内偷窥港台综合视频在线播放| 欧美日韩国产首页在线观看| 自拍偷拍亚洲综合| 成a人片国产精品| 国产色爱av资源综合区| 狠狠色综合日日| 日韩亚洲欧美在线观看| 无吗不卡中文字幕| 色婷婷av一区二区三区软件| 国产精品沙发午睡系列990531| 激情五月激情综合网| 日韩一区二区三区免费看| 午夜精品久久久久| 91.xcao| 一区二区三区日韩精品视频| 97精品久久久久中文字幕| 国产三级精品视频| 国内成人自拍视频| 欧美视频在线一区| 国产精品美女一区二区在线观看| 久久激情综合网| 欧美精品视频www在线观看| 午夜一区二区三区视频| 欧美日韩视频第一区| 日韩成人免费看| 日韩一区二区免费在线观看| 国产原创一区二区| 日韩一区二区三区在线观看| 久久69国产一区二区蜜臀| 欧美高清性hdvideosex| 亚洲一区中文日韩| 欧美一区二区三区四区久久| 日本欧洲一区二区| 精品剧情在线观看| 国产91高潮流白浆在线麻豆| 亚洲色图视频网| 欧美网站大全在线观看| 三级在线观看一区二区 | 国产精品第五页| 色菇凉天天综合网| 日韩电影一区二区三区四区| 亚洲精品在线一区二区| 国产麻豆日韩欧美久久| 亚洲私人影院在线观看| 成人免费观看av| 国产精品五月天| 国产一区二区三区av电影| 国产精品女同一区二区三区| 在线观看亚洲a| 麻豆精品视频在线观看免费| 国产香蕉久久精品综合网| 色av成人天堂桃色av| 麻豆免费看一区二区三区| 亚洲国产精品国自产拍av| 在线观看网站黄不卡| 美国欧美日韩国产在线播放| 一区在线播放视频| 欧美日韩国产免费一区二区 | 成人久久18免费网站麻豆| 亚洲一级不卡视频| 国产网站一区二区| 欧美人妖巨大在线| av亚洲精华国产精华| 日本视频一区二区三区| 国产精品麻豆视频| 欧美一区二区三区白人| 99久久777色| 国产麻豆成人精品| 午夜电影久久久| 国产精品美女久久久久高潮| 欧美肥妇毛茸茸| 日本韩国视频一区二区| 国产一区不卡精品| 日韩av一区二区三区四区| 亚洲欧美综合另类在线卡通| 久久免费视频色| 欧美区一区二区三区| 一本大道综合伊人精品热热| 国产福利一区在线| 六月丁香综合在线视频| 亚洲午夜视频在线观看| 中文字幕视频一区| 国产精品欧美极品| 久久久五月婷婷| 久久亚洲免费视频| 国产福利视频一区二区三区| 亚洲男人天堂av网| 国产精品色婷婷| 国产欧美一区二区精品忘忧草| 欧美成人欧美edvon| 欧美一级xxx| 9191成人精品久久| 在线电影院国产精品| 欧美日韩一级二级| 欧美三片在线视频观看| 91福利国产成人精品照片| 97国产一区二区| 国产精品一品视频| 日韩一区精品字幕| 奇米777欧美一区二区| 男人操女人的视频在线观看欧美| 亚洲成人av免费| 一区二区三区欧美亚洲| 一区二区三区 在线观看视频| 亚洲精品亚洲人成人网| 亚洲欧美日韩国产中文在线| 亚洲综合在线观看视频| 一区二区三区欧美亚洲| 亚洲一卡二卡三卡四卡五卡| 视频一区二区欧美| 久久国产精品露脸对白| 国产最新精品精品你懂的| 国产一区二区调教| 成人一区二区三区视频| 99国内精品久久| 欧美性受极品xxxx喷水| 欧美一区二区在线免费观看| 精品国产一区二区亚洲人成毛片| 91精品黄色片免费大全| 777精品伊人久久久久大香线蕉| 欧美一卡在线观看| 国产三级一区二区| 最新国产成人在线观看| 亚洲男女一区二区三区| 亚洲一级电影视频| 久久激五月天综合精品| 成人白浆超碰人人人人| 欧美日韩亚洲综合在线| 久久综合九色综合欧美亚洲| 国产精品久久久久9999吃药| 亚洲电影你懂得| 韩国av一区二区| 色欧美88888久久久久久影院| 91麻豆精品国产自产在线 | 91麻豆福利精品推荐| 欧美乱妇23p| 欧美极品美女视频| 亚洲高清视频中文字幕| 激情综合网天天干| 国产激情一区二区三区四区| 91色视频在线| 日韩久久久久久| 亚洲色图一区二区| 天天色综合天天| 国产一区二区三区免费在线观看| 国产一区激情在线| 欧美日韩在线播放一区| 国产日韩欧美精品在线| 日韩有码一区二区三区| 91在线视频观看| 亚洲精品一区二区三区香蕉| 一区二区三区在线不卡| 国产精品自拍一区| 欧美视频在线一区| 亚洲丝袜自拍清纯另类| 不卡av电影在线播放| 国产日韩在线不卡| 国产一区二区免费看| 精品国产网站在线观看| 久久激五月天综合精品| 日韩一级黄色大片| 日韩国产欧美在线播放| 欧美电影影音先锋| 日韩av一级电影| 日韩一级欧美一级| 九九精品一区二区| 久久午夜国产精品| 丁香婷婷综合激情五月色| 国产日韩综合av|