当前位置: 首页 > news >正文

塘厦 网站建设 百度推广新建网页的方法有哪些

塘厦 网站建设 百度推广,新建网页的方法有哪些,谷歌广告联盟,包头网站建设哪家好Collections.sort 事实上Collections.sort方法底层就是调用的Arrays.sort方法#xff0c;而Arrays.sort使用了两种排序方法#xff0c;快速排序和优化的归并排序。 快速排序主要是对那些基本类型数据#xff08;int,short,long等#xff09;排序#xff0c; 而归并排序用于…Collections.sort 事实上Collections.sort方法底层就是调用的Arrays.sort方法而Arrays.sort使用了两种排序方法快速排序和优化的归并排序。 快速排序主要是对那些基本类型数据int,short,long等排序 而归并排序用于对Object类型进行排序。 使用不同类型的排序算法主要是由于快速排序是不稳定的而归并排序是稳定的。这里的稳定是指比较相等的数据在排序之后仍然按照排序之前的前后顺序排列。对于基本数据类型稳定性没有意义而对于Object类型稳定性是比较重要的因为对象相等的判断可能只是判断关键属性最好保持相等对象的非关键属性的顺序与排序前一致另外一个原因是由于归并排序相对而言比较次数比快速排序少移动对象引用的移动次数比快速排序多而对于对象来说比较一般比移动耗时。 public static T extends Comparable? super T void sort(ListT list) {list.sort(null); } List#sort default void sort(Comparator? super E c) {Object[] a this.toArray();Arrays.sort(a, (Comparator) c);ListIteratorE i this.listIterator();for (Object e : a) {i.next();i.set((E) e);} }public static T void sort(T[] a, Comparator? super T c) {if (c null) {sort(a);} else {if (LegacyMergeSort.userRequested)legacyMergeSort(a, c);elseTimSort.sort(a, 0, a.length, c, null, 0, 0);} }public static void sort(Object[] a) {if (LegacyMergeSort.userRequested)legacyMergeSort(a);elseComparableTimSort.sort(a, 0, a.length, null, 0, 0); } TimSort 结合了归并排序和插入排序的混合算法它基于一个简单的事实实际中大部分数据都是部分有序升序或降序的。 TimSort 算法为了减少对升序部分的回溯和对降序部分的性能倒退将输入按其升序和降序特点进行了分区。排序的输入的单位不是一个个单独的数字而是一个个的块-分区。其中每一个分区叫一个run。针对这些 run 序列每次拿一个 run 出来按规则进行合并。每次合并会将两个 run合并成一个 run。合并的结果保存到栈中。合并直到消耗掉所有的 run这时将栈上剩余的 run合并到只剩一个 run 为止。这时这个仅剩的 run 便是排好序的结果。 综上述过程Timsort算法的过程包括 0如果数组长度小于某个值直接用二分插入排序算法 1找到各个run并入栈 2按规则合并run /*** Sorts the given range, using the given workspace array slice* for temp storage when possible. This method is designed to be* invoked from public methods (in class Arrays) after performing* any necessary array bounds checks and expanding parameters into* the required forms.** param a the array to be sorted* param lo the index of the first element, inclusive, to be sorted* param hi the index of the last element, exclusive, to be sorted* param work a workspace array (slice)* param workBase origin of usable space in work array* param workLen usable size of work array* since 1.8*/ static void sort(Object[] a, int lo, int hi, Object[] work, int workBase, int workLen) {assert a ! null lo 0 lo hi hi a.length;int nRemaining hi - lo;if (nRemaining 2)return; // Arrays of size 0 and 1 are always sorted// If array is small, do a mini-TimSort with no mergesif (nRemaining MIN_MERGE) {int initRunLen countRunAndMakeAscending(a, lo, hi);binarySort(a, lo, hi, lo initRunLen);return;}/*** March over the array once, left to right, finding natural runs,* extending short natural runs to minRun elements, and merging runs* to maintain stack invariant.*/ComparableTimSort ts new ComparableTimSort(a, work, workBase, workLen);int minRun minRunLength(nRemaining);do {// Identify next runint runLen countRunAndMakeAscending(a, lo, hi);// If run is short, extend to min(minRun, nRemaining)if (runLen minRun) {int force nRemaining minRun ? nRemaining : minRun;binarySort(a, lo, lo force, lo runLen);runLen force;}// Push run onto pending-run stack, and maybe mergets.pushRun(lo, runLen);ts.mergeCollapse();// Advance to find next runlo runLen;nRemaining - runLen;} while (nRemaining ! 0);// Merge all remaining runs to complete sortassert lo hi;ts.mergeForceCollapse();assert ts.stackSize 1; } /*** Creates a TimSort instance to maintain the state of an ongoing sort.** param a the array to be sorted* param work a workspace array (slice)* param workBase origin of usable space in work array* param workLen usable size of work array*/ private ComparableTimSort(Object[] a, Object[] work, int workBase, int workLen) {this.a a;// Allocate temp storage (which may be increased later if necessary)int len a.length;int tlen (len 2 * INITIAL_TMP_STORAGE_LENGTH) ?len 1 : INITIAL_TMP_STORAGE_LENGTH;if (work null || workLen tlen || workBase tlen work.length) {tmp new Object[tlen];tmpBase 0;tmpLen tlen;}else {tmp work;tmpBase workBase;tmpLen workLen;}/** Allocate runs-to-be-merged stack (which cannot be expanded). The* stack length requirements are described in listsort.txt. The C* version always uses the same stack length (85), but this was* measured to be too expensive when sorting mid-sized arrays (e.g.,* 100 elements) in Java. Therefore, we use smaller (but sufficiently* large) stack lengths for smaller arrays. The magic numbers in the* computation below must be changed if MIN_MERGE is decreased. See* the MIN_MERGE declaration above for more information.* The maximum value of 49 allows for an array up to length* Integer.MAX_VALUE-4, if array is filled by the worst case stack size* increasing scenario. More explanations are given in section 4 of:* http://envisage-project.eu/wp-content/uploads/2015/02/sorting.pdf*/int stackLen (len 120 ? 5 :len 1542 ? 10 :len 119151 ? 24 : 49);runBase new int[stackLen];runLen new int[stackLen]; }MergeSort private static void legacyMergeSort(Object[] a) {Object[] aux a.clone();mergeSort(aux, a, 0, a.length, 0); }private static void mergeSort(Object[] src,Object[] dest,int low,int high,int off) {int length high - low;// 7// Insertion sort on smallest arraysif (length INSERTIONSORT_THRESHOLD) {for (int ilow; ihigh; i)for (int ji; jlow ((Comparable) dest[j-1]).compareTo(dest[j])0; j--)swap(dest, j, j-1);return;}// Recursively sort halves of dest into srcint destLow  low;int destHigh high;low  off;high off;int mid (low high) 1;mergeSort(dest, src, low, mid, -off);mergeSort(dest, src, mid, high, -off);// If list is already sorted, just copy from src to dest.  This is an// optimization that results in faster sorts for nearly ordered lists.if (((Comparable)src[mid-1]).compareTo(src[mid]) 0) {System.arraycopy(src, low, dest, destLow, length);return;}// Merge sorted halves (now in src) into destfor(int i destLow, p low, q mid; i destHigh; i) {if (q high || p mid ((Comparable)src[p]).compareTo(src[q])0)dest[i] src[p];elsedest[i] src[q];} } 总结 小于60使用插入排序插入排序是稳定的     大于60的数据量会根据数据类型选择排序方式          基本类型使用快速排序。因为基本类型。1、2都是指向同一个常量池不需要考虑稳定性。          Object类型使用归并排序。因为归并排序具有稳定性。     注意不管是快速排序还是归并排序。在二分的时候小于60的数据量依旧会使用插入排序
http://www.yutouwan.com/news/169815/

相关文章:

  • 制作的网站如何访问南充网站建设费用
  • 阿里云个人网站备案过程全记录wordpress移动端底部导航栏
  • 要建设一个网站需要什么手续怀柔网站制作
  • 两学一做网站安徽省怎么制作网页内容
  • 规范网站建设的通知成都软件开发公司排名
  • 网站建设外包名词解释成品网站是什么意思
  • 国外交互设计网站欣赏html网页设计代码作业正能量
  • 网站欧美风格免费解析网站制作
  • 宁波高等级公路建设指挥部网站wordpress关闭评论审核
  • 佛山网站制作哪家好吉林省建设厅网站二建管理系统
  • wordpress能做多大的站网站只做1单生意被罚4万两级违法
  • 做企业网站的意义网页设计师招聘条件
  • 河北建设厅网站没有注册怎么做网站设计
  • 网站建设费算办公费吗网站制作手机
  • 信誉好的手机网站建设网站 备案已注销
  • 给公司做门户网站什么是网站的后台
  • 专门做中式的设计网站外贸公司怎么注册
  • 营口网站开发免费优化
  • 吉林省电力建设总公司网站3d房屋建筑设计软件
  • 自然人做音频网站违法吗做破解的网站
  • 天津国际工程建设监理公司网站网站开发的毕设开题报告
  • 虚拟服务器和如何创建网站中国建设学会查询网站
  • 免费装饰公司网站模板网络运营专业
  • 特产网站建设的目的线上设计师接单
  • 单位做网站注意什么动态和静态网站的区别
  • 免费网站怎么做排名三里屯网站建设公司
  • 绵阳市城市建设档案馆网站怎样做代刷网站长
  • js网站源码已到期高清品牌网站设计建设
  • 旅游做攻略网站好品牌网站建设有哪些方面
  • 网站设计与维护专业网站开发哪里有