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

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

?? 8.cpp

?? 《數據結構與程序設計》書本所有源代碼!!!!
?? CPP
字號:
/* Program extracts from Chapter 8 of   "Data Structures and Program Design in C++"   by Robert L. Kruse and Alexander J. Ryba   Copyright (C) 1999 by Prentice-Hall, Inc.  All rights reserved.   Extracts from this file may be used in the construction of other programs,   but this code will not compile or execute as given here. */// Section 8.1:template <class Record>class Sortable_list:public List<Record> {public:   //  Add prototypes for sorting methods here. private: //  Add prototypes for auxiliary functions here.};// Section 8.2:template <class Record>void Sortable_list<Record>::insertion_sort()/*Post: The entries of the Sortable_list have been rearranged so that      the keys in all the  entries are sorted into nondecreasing order.Uses: Methods for the class Record; the contiguous List implementation of      Chapter 6*/{   int first_unsorted;    //  position of first unsorted entry   int position;          //  searches sorted part of list   Record current;        //  holds the entry temporarily removed from list   for (first_unsorted = 1; first_unsorted < count; first_unsorted++)      if (entry[first_unsorted] < entry[first_unsorted - 1]) {         position = first_unsorted;         current = entry[first_unsorted];         //  Pull unsorted entry out of the list.         do {               //  Shift all entries until the proper position is found.            entry[position] = entry[position - 1];            position--;                           //  position is empty.         } while (position > 0 && entry[position - 1] > current);         entry[position] = current;      }}template <class Record>void Sortable_list<Record>::insertion_sort()/*Post: The entries of the Sortable_list have been rearranged so that      the keys in all the entries are sorted into nondecreasing order.Uses: Methods for the class Record; the linked List implementation of Chapter 6.*/{   Node <Record> *first_unsorted,  //  the first unsorted node to be inserted                 *last_sorted,     //  tail of the sorted sublist                 *current,         //  used to traverse the sorted sublist                 *trailing;        //  one position behind current   if (head != NULL) {          //  Otherwise, the empty list is already sorted.      last_sorted = head;       //  The first node alone makes a sorted sublist.      while (last_sorted->next != NULL) {         first_unsorted = last_sorted->next;         if (first_unsorted->entry < head->entry) {            //  Insert *first_unsorted at the head of the sorted list:            last_sorted->next = first_unsorted->next;            first_unsorted->next = head;            head = first_unsorted;         }         else {            //  Search the sorted sublist to insert *first_unsorted:            trailing = head;            current = trailing->next;            while (first_unsorted->entry > current->entry) {               trailing = current;               current = trailing->next;            }            //  *first_unsorted now belongs between *trailing and *current.            if (first_unsorted == current)               last_sorted = first_unsorted;  //  already in right position            else {               last_sorted->next = first_unsorted->next;               first_unsorted->next = current;               trailing->next = first_unsorted;            }         }      }   }}// Section 8.3:template <class Record>void Sortable_list<Record>::selection_sort()/*Post: The entries of the Sortable_list have been rearranged so that      the keys in all the entries are sorted into nondecreasing order.Uses: max_key, swap.*/{   for (int position = count - 1; position > 0; position--) {      int max = max_key(0, position);      swap(max, position);   }}template <class Record>int Sortable_list<Record>::max_key(int low, int high)/*Pre:  low and high are valid positions in the Sortable_list and low <= high.Post: The position of the entry between low and high with the largest      key is returned.Uses: The class Record, the contiguous List implementation of Chapter 6.*/{   int largest, current;   largest = low;   for (current = low + 1; current <= high; current++)      if (entry[largest] < entry[current])         largest = current;   return largest;}template <class Record>void Sortable_list<Record>::swap(int low, int high)/*Pre:  low and high are valid positions in the Sortable_list.Post: The entry at position low is swapped with the entry at position high.Uses: The contiguous List implementation of Chapter 6.*/{   Record temp;   temp = entry[low];   entry[low] = entry[high];   entry[high] = temp;}// Section 8.4:template <class Record>void Sortable_list<Record>::shell_sort()/*Post: The entries of the Sortable_list have been rearranged so that      the keys in all the entries are sorted into nondecreasing order.Uses: sort_interval*/{   int increment,    //  spacing of entries in sublist       start;        //  starting point of sublist   increment = count;   do {      increment = increment / 3 + 1;      for (start = 0; start < increment; start++)         sort_interval(start, increment);  //  modified insertion sort   } while (increment > 1);}// Section 8.6:void Sortable_list::sort(){   if the list has length greater than 1 {      partition the list into lowlist, highlist;      lowlist.sort();      highlist.sort();      combine(lowlist, highlist);   }}// Section 8.7:template <class Record>void Sortable_list<Record>::merge_sort()/*Post: The entries of the sortable list have been rearranged so that      their keys are sorted into nondecreasing order.Uses: The linked List implementation of Chapter 6 and recursive_merge_sort.*/{   recursive_merge_sort(head);}template <class Record>void Sortable_list<Record>::recursive_merge_sort(Node<Record> *&sub_list)/*Post: The nodes referenced by sub_list have been rearranged so that their      keys are sorted into nondecreasing order.  The pointer parameter      sub_list is reset to point at the node containing the smallest key.Uses: The linked List implementation of Chapter 6;      the functions divide_from, merge, and recursive_merge_sort.*/{   if (sub_list != NULL && sub_list->next != NULL) {      Node<Record> *second_half = divide_from(sub_list);      recursive_merge_sort(sub_list);      recursive_merge_sort(second_half);      sub_list = merge(sub_list, second_half);   }}template <class Record>Node<Record> *Sortable_list<Record>::divide_from(Node<Record> *sub_list)/*Post: The list of nodes referenced by sub_list has been reduced      to its first half, and a pointer to the first node in the second half      of the sublist is returned.  If the sublist has an odd number of      entries, then its first half will be one entry larger than its second.Uses: The linked List implementation of Chapter 6.*/{   Node<Record> *position, //  traverses the entire list                *midpoint, //  moves at half speed of position to midpoint                *second_half;   if ((midpoint = sub_list) == NULL) return NULL;  //  List is empty.   position = midpoint->next;   while (position != NULL) { //  Move position twice for midpoint's one move.      position = position->next;      if (position != NULL) {         midpoint = midpoint->next;         position = position->next;      }   }   second_half = midpoint->next;   midpoint->next = NULL;   return second_half;}template <class Record>Node<Record> *Sortable_list<Record>::merge(Node<Record> *first,                                           Node<Record> *second)/*Pre:  first and second point to ordered lists of nodes.Post: A pointer to an ordered list of nodes is returned.      The ordered list contains all entries that were referenced by      first and second.  The original lists of nodes referenced      by first and second are no longer available.Uses: Methods for Record class; the linked List implementation of Chapter 6.*/{   Node<Record> *last_sorted; //  points to the last node of sorted list   Node<Record> combined;     //  dummy first node, points to merged list   last_sorted = &combined;   while (first != NULL && second != NULL) { //  Attach node with smaller key      if (first->entry <= second->entry) {         last_sorted->next = first;         last_sorted = first;         first = first->next;   //  Advance to the next unmerged node.      }      else {         last_sorted->next = second;         last_sorted = second;         second = second->next;      }   }//  After one list ends, attach the remainder of the other.   if (first == NULL)      last_sorted->next = second;   else      last_sorted->next = first;   return combined.next;}// Section 8.8:template <class Record>void Sortable_list<Record>::quick_sort()/*Post: The entries of the Sortable_list have been rearranged so      that their keys are sorted into nondecreasing order.Uses: The contiguous List implementation of Chapter 6, recursive_quick_sort.*/{   recursive_quick_sort(0, count - 1);}template <class Record>void Sortable_list<Record>::recursive_quick_sort(int low, int high)/*Pre:  low and high are valid positions in the Sortable_list.Post: The entries of the Sortable_list have been      rearranged so that their keys are sorted into nondecreasing order.Uses: The contiguous List implementation of Chapter 6,      recursive_quick_sort, and partition.*/{   int pivot_position;   if (low < high) {   //   Otherwise, no sorting is needed.      pivot_position = partition(low, high);      recursive_quick_sort(low, pivot_position - 1);      recursive_quick_sort(pivot_position + 1, high);   }}template <class Record>int Sortable_list<Record>::partition(int low, int high)/*Pre:  low and high are valid positions of the Sortable_list, with low <= high.Post: The center (or left center) entry in the range between indices      low and high of the Sortable_list      has been chosen as a pivot.  All entries of the Sortable_list      between indices low and high, inclusive, have been      rearranged so that those with keys less than the pivot come      before the pivot and the remaining entries come      after the pivot.  The final position of the pivot is returned.Uses: swap(int i, int j) (interchanges entries in positions      i and j of a Sortable_list), the contiguous List implementation      of Chapter 6, and methods for the class Record.*/{   Record pivot;   int i,            //  used to scan through the list       last_small;   //  position of the last key less than pivot   swap(low, (low + high) / 2);   pivot = entry[low];   //  First entry is now pivot.   last_small = low;   for (i = low + 1; i <= high; i++)/*At the beginning of each iteration of this loop, we have the followingconditions:        If low < j <= last_small then entry[j].key < pivot.        If last_small < j < i then entry[j].key >= pivot.*/      if (entry[i] < pivot) {         last_small = last_small + 1;         swap(last_small, i);  //  Move large entry to right and small to left.      }   swap(low, last_small);      //  Put the pivot into its proper position.   return last_small;}// Section 8.9:template <class Record>void Sortable_list<Record>::heap_sort()/*Post: The entries of the Sortable_list have been rearranged so      that their keys are sorted into nondecreasing order.Uses: The contiguous List implementation of Chapter 6,build_heap,      and insert_heap.*/{   Record current;    //  temporary storage for moving entries   int last_unsorted; //  Entries beyond last_unsorted have been sorted.   build_heap();      //  First phase:  Turn the list into a heap.   for (last_unsorted = count - 1; last_unsorted > 0; last_unsorted--) {      current = entry[last_unsorted];   //  Extract the last entry from the list.      entry[last_unsorted] = entry[0];     //  Move top of heap to the end      insert_heap(current, 0, last_unsorted - 1);  //  Restore the heap   }}template <class Record>void Sortable_list<Record>::insert_heap(const Record &current, int low, int high)/*Pre:  The entries of the Sortable_list between indices low + 1 and high,      inclusive, form a heap. The entry in position low will be discarded.Post: The entry current has been inserted into the Sortable_list      and the entries rearranged      so that the entries between indices low and high, inclusive,      form a heap.Uses: The class Record, and the contiguous List implementation of Chapter 6.*/{   int large;           //  position of child of entry[low] with the larger key   large = 2 * low + 1; //  large is now the left child of low.   while (large <= high) {      if (large < high && entry[large] < entry[large + 1])         large++;       //  large is now the child of low with the largest key.      if (current >= entry[large])         break;         //  current belongs in position low.      else {            //  Promote entry[large] and move down the tree.         entry[low] = entry[large];         low = large;         large = 2 * low + 1;      }   }   entry[low] = current;}template <class Record>void Sortable_list<Record>::build_heap()/*Post: The entries of the Sortable_list have been rearranged      so that it becomes a heap.Uses: The contiguous List implementation of Chapter 6, and insert_heap.*/{   int low;   //  All entries beyond the position low form a heap.   for (low = count / 2 - 1; low >= 0; low--) {      Record current = entry[low];      insert_heap(current, low, count - 1);   }}/*************************************************************************/

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
天堂av在线一区| 色诱亚洲精品久久久久久| 国产美女在线观看一区| 91久久精品一区二区| 日韩美女视频一区二区在线观看| 国产精品免费久久| 喷水一区二区三区| 色噜噜夜夜夜综合网| 国产亚洲自拍一区| 久久丁香综合五月国产三级网站| 色美美综合视频| 日本一区二区三区免费乱视频 | 国产精品大尺度| 日韩精品国产欧美| 欧洲一区在线观看| 国产精品视频免费| 国内欧美视频一区二区| 欧美日韩一区高清| 亚洲欧美国产77777| 高清久久久久久| 久久人人97超碰com| 视频一区在线播放| 在线观看欧美精品| 亚洲婷婷国产精品电影人久久| 精品在线观看视频| 日韩欧美激情四射| 热久久久久久久| 欧美精品免费视频| 亚洲va欧美va人人爽| 91蜜桃婷婷狠狠久久综合9色| 久久精品视频一区二区| 精彩视频一区二区三区| 精品裸体舞一区二区三区| 亚洲成人精品在线观看| 在线免费观看日本一区| 亚洲日本韩国一区| 色婷婷激情综合| 亚洲婷婷在线视频| 日韩av中文字幕一区二区三区| 日本韩国一区二区三区视频| 亚洲人成影院在线观看| 95精品视频在线| 亚洲欧美日韩在线| 欧美在线制服丝袜| 午夜久久久影院| 欧美一级理论片| 日产精品久久久久久久性色| 日韩久久精品一区| 国产精品一二一区| 中文字幕精品综合| 91在线免费看| 亚洲国产欧美在线人成| 欧美日韩国产综合草草| 丝袜a∨在线一区二区三区不卡| 日韩欧美一二三四区| 国内偷窥港台综合视频在线播放| 欧美国产国产综合| 91久久精品一区二区二区| 午夜精品久久一牛影视| 日韩欧美一区二区视频| 国产成人日日夜夜| 一片黄亚洲嫩模| 91精品在线免费| 国产成人在线免费| 亚洲精品国产一区二区三区四区在线| 欧美四级电影网| 久久99国产精品久久99| 国产精品久久三| 欧美夫妻性生活| 国产精品一区二区三区99| 亚洲精品中文字幕乱码三区| 欧美精品一二三四| 国产一区不卡视频| 亚洲综合色成人| 日韩亚洲欧美一区二区三区| 成人黄色大片在线观看| 亚洲福利视频三区| 国产女同互慰高潮91漫画| 91国偷自产一区二区开放时间 | 欧美视频在线观看一区二区| 毛片av一区二区| 亚洲天堂2014| 精品久久久久香蕉网| 一本色道久久综合狠狠躁的推荐| 国产在线播放一区三区四| 亚洲第一福利一区| 国产精品视频一二| 精品99一区二区| 欧美日韩一区不卡| www.在线欧美| 精品一区二区三区欧美| 日韩av一区二区三区四区| 国产精品色噜噜| 精品久久久久99| 欧美日韩精品一区二区三区| 波多野结衣一区二区三区| 久草这里只有精品视频| 亚洲国产精品久久久久婷婷884| 国产欧美一区视频| 日韩欧美卡一卡二| 91 com成人网| 91福利国产精品| thepron国产精品| 国产精品99久久久久久久女警| 日韩国产成人精品| 午夜免费久久看| 亚洲国产综合色| 一区二区三区四区在线| 国产精品乱码一区二三区小蝌蚪| 欧美成人一区二区三区片免费 | 免费不卡在线观看| 亚洲成av人影院在线观看网| 一区二区在线观看av| 一区在线中文字幕| 国产精品青草综合久久久久99| 精品久久人人做人人爽| 日韩欧美的一区二区| 8x8x8国产精品| 在线播放国产精品二区一二区四区| 色综合久久中文综合久久牛| youjizz国产精品| 菠萝蜜视频在线观看一区| 高清av一区二区| 成人综合在线观看| av网站免费线看精品| 成熟亚洲日本毛茸茸凸凹| 高清不卡一区二区| 成人美女视频在线观看| 成人精品电影在线观看| 不卡在线视频中文字幕| 91在线观看下载| 色综合激情久久| 欧美羞羞免费网站| 欧美日本免费一区二区三区| 欧美一区永久视频免费观看| 日韩午夜电影在线观看| 久久久亚洲精品一区二区三区| 欧美国产日韩a欧美在线观看 | 麻豆国产一区二区| 国产精品主播直播| 92国产精品观看| 欧美午夜视频网站| 欧美成人艳星乳罩| 国产精品女主播av| 亚洲一二三专区| 久久99精品久久久久婷婷| 高清日韩电视剧大全免费| 欧美系列日韩一区| 精品不卡在线视频| 亚洲私人黄色宅男| 国产福利91精品| 国产在线精品不卡| 欧美私模裸体表演在线观看| 国产精品一区二区黑丝| 9i在线看片成人免费| 欧美日韩一级片在线观看| www久久久久| 亚洲精品视频在线| 精品一区二区免费在线观看| 97久久精品人人做人人爽| 91精品国产日韩91久久久久久| 国产日产欧美一区| 日韩激情视频网站| 成人av在线资源网| 欧美一区二区福利视频| 中文字幕av一区二区三区高| 午夜欧美在线一二页| 成人免费黄色大片| 69久久夜色精品国产69蝌蚪网| 国产日产欧美一区| 日本一不卡视频| 99精品视频一区二区三区| 日韩欧美高清一区| 亚洲精品免费一二三区| 国产一区999| 91麻豆精品国产91久久久资源速度| 国产日韩高清在线| 日本aⅴ免费视频一区二区三区| 成人av电影免费观看| 欧美成人a∨高清免费观看| 伊人开心综合网| 国产不卡在线播放| 日韩视频国产视频| 亚洲制服丝袜av| 99久久精品国产观看| 国产喷白浆一区二区三区| 久久成人免费电影| 欧美日本在线一区| 亚洲高清免费一级二级三级| 91女厕偷拍女厕偷拍高清| 久久综合九色综合欧美亚洲| 日韩高清电影一区| 欧美午夜电影网| 一区二区在线观看视频在线观看| hitomi一区二区三区精品| 久久久99精品免费观看| 国产一区二区电影| 久久亚洲二区三区| 久久99国产精品麻豆| 欧美电视剧在线观看完整版|