- 0
- 0
- 约4.24千字
- 约 58页
- 2021-07-12 发布于河北
- 举报
Programming in Java;Agenda;Computing Factorial;Factorial -- Iteration;Recursion 遞迴概念;Factorial – Recursion, in Java;N Factorial ( Recursive版 );歐幾里得的最大公約數;最大公約數 non-recursive版;Recursive 也可以很有趣(1/3);Recursive 也可以很有趣(2/3);;問題與思考 (Recursion);Factorial – cache ans in a Table;Computing Primes (1/3);Computing Primes (2/3);Computing Primes (3/3);Example: Find Primes (1/2);Example: Find Primes (2/2);Sorting Numbers;Selection Sort (1/4);Selection Sort (2/4);Selection Sort (3/4);Selection Sort (4/4);;;Insertion Sort;Test the Insertion Sort;Bubble Sort; Algorithm quick_sort(array A, from, to)
Input: from - pointer to the starting position of array A
to - pointer to the end position of array A
Output: sorted array: A’
1. Choose any one element as the pivot;
2. Find the first element a = A[i] larger than or equal to pivot from
A[from] to A[to];
3. Find the first element b = A[j] smaller than or equal to pivot from
A[to] to A[from];
4. If i j then exchange a and b;
5. Repeat step from 2 to 4 until j = i;
6. If from j then recursive call quick_sort(A, from, j);
7. If i to then recursive call quick_sort(A, i, to);;;; public class QuickSorter {
public static void sort (int[ ] a, int from, int to) {
if ((a == null) || (a.length 2)) return;
int i = from, j = to;
int pivot = a[(from + to)/2];
do {
while ((i to) (a[i] pivot)) i++;
while ((j from) (a[j] = pivot)) j--;
if (i j) { int tmp =a[i]; a [i] = a[j]; a[j] = tmp;}
i++; j--;
}while (i = j);
if (from j) sort(a, from, j);
if (i to) sort(a, i, to); }
} ;14; public class BQSorter {
public static void sort (int[ ] a, int from, int to) {
if ((a == null) || (a.length 2) || from = to) return;
int k = (from + to)/2; int tmp =a[to]; a [to] = a[k]; a[k] = tmp;
int pivot = a[to]; int i = from, j = to-1;
while(i j ) {
while ((i j) (a[i] pivot)) i++;
while ((i j) (a[j] = pivot)) j--;
if (i j) { tmp =a[i]; a [i]
您可能关注的文档
- 主要网络设备介绍.pptx
- 主题餐厅市场营销创业计划书.pptx
- 主要组织相容性复合体MHC.pptx
- 乘坐电梯的安全自护知识.pptx
- 九型人格(心理学)准的不行.pptx
- 乘用车尼日利亚市场运营方案XXXX0425.pptx
- 九合一POS进销存CRM会员管理系统.pptx
- 九型人格(学会看人).pptx
- 主要组织相容性复合物.pptx
- 九型人格2(解释版).pptx
- 2025年北京市门头沟区中考一模英语试题.docx
- 2025年北京市门头沟区中考二模英语试题.docx
- 2025年北京市丰台区中考二模英语试题.docx
- 2025年中考英语考前冲刺模拟卷 (北京专用) 解析卷.docx
- 2025年中考英语考前冲刺模拟卷 (北京专用) 原卷.docx
- 2025年肩颈按摩仪行业社媒趋势数据分析.docx
- 2025年人身险行业信用回顾与2026年展望.docx
- 合同法买卖合同培训课件.ppt
- 2025年全球食物系统与SDG研究报告-食物供给、食者健康、生态平衡的整体治理.docx
- 2025下半年四川乐山市川投峨眉铁合金(集团)有限责任公司对考前自测高频考点模拟试题最新.docx
最近下载
- 《叶圣陶语文教育论集》序原文全文阅读.docx VIP
- 《五年级数学上册计算题每日一练(共28套)》通用.docx VIP
- HK-2301便携式水质综合分析仪说明书(2015.2.12).pdf VIP
- 量化投资 课件 第7、8章 APT理论和多因子收益率模型、基于信息的预测.pptx
- 小学二年级数学下册乘法口算练习题(每日一练,共27份).pdf VIP
- 小学三年级数学下册乘法计算专项练习题(每日一练,共15份).pdf VIP
- 小学三年级数学下册乘法计算专项练习题(每日一练,共26份).docx VIP
- 子宫腺肌病治疗与管理教程.ppt
- 三年级数学下册应用题专项练习题(每日一练) (9).docx VIP
- 三年级数学下册应用题专项练习题(每日一练) (5).docx VIP
原创力文档

文档评论(0)