当前位置:网站首页>CPT 102_ LEC 17
CPT 102_ LEC 17
2022-06-11 02:50:00 【NONE_ WHY】
1. Binary Search
2. Sorting
2.1. Ways of sorting
2.1.1. Selecting sorts
- Find the next largest/smallest item and put in place
- Builds the correct list in order
2.1.2. Inserting Sorts
- For each item, insert it into an ordered sublis
- Builds a sorted list, but keeps changing it
2.1.3. Compare and Swap Sorts
- Find two items that are out of order, and swap them
- Keeps “improving” the list
2.1.4. Radix Sorts
- Look at the item and work out where it should go
- Only works on some kinds of values
2.2. Analysing Sorting Algorithms
- Efficiency
- Requirements on Data
- Space Usage
2.3. Implementation
2.3.1. Selection Sort
- Code
public void selectionSort(E[ ] data, int size, Comparator<E> comp){ // for each position, from 0 up, find the next smallest item // and swap it into place for (int place=0; place<size-1; place++){ int minIndex = place; for (int sweep=place+1; sweep<size; sweep++){ if (comp.compare(data[sweep], data[minIndex]) < 0) minIndex=sweep; } swap(data, place, minIndex); } }
- Analysis
-

-
2.3.2. Bubble Sort
- Code
-
public void bubbleSort(E[] data, int size, Comparator<E> comp){ // Repeatedly scan array, swapping adjacent items if out of order // Builds a sorted region from the end for (int top=size-1; top>0; top--){ for (int sweep=0; sweep<top; sweep++){ if (comp.compare(data[sweep], data[sweep+1]) >0) { swap(data, sweep, sweep+1); } } } }
-
- Analysis
-

-
边栏推荐
- Kotlin apply method
- Arduino使用NRF24L01模块进行无线通信
- 完成千万元A轮融资,小象生活能否成为折扣界的“永辉”?
- 【189. 轮转数组】
- Can annuity insurance financial products be compounded? What is the interest rate?
- HUST软件工程(实验2)--TDD测试驱动开发实验。
- CPT 102_LEC 20
- CPT 102_LEC 13-14
- 6 best WordPress Image optimizer plug-ins to improve WordPress website performance
- 微信小程序
猜你喜欢

mysql重装时写my.ini配置文件出错

Metal organic framework materials (fe-mil-53, mg-mof-74, ti-kumof-1, fe-mil-100, fe-mil-101) supported on isoflurane / methotrexate / doxorubicin (DOX) / paclitaxel / ibuprofen / camptothecin

APP测试_测试点总结

软件测试英语常见词汇

WordPress article directory plug-in luckywp table of contents setup tutorial

Modify release opening animation

Necessity for banks to choose electronic bidding procurement

Project load failed

Looking at the ups and downs of the mobile phone accessories market from the green Union's sprint for IPO
![[189. rotation array]](/img/cc/0da616ad9adc9c9d352e54f58dbe41.png)
[189. rotation array]
随机推荐
Use of CIN and cout
P4338 [zjoi2018] history (tree section) (violence)
Metal organic framework MOF Al (Diba), MOF Zr (Diba), MOF Fe (Diba) loaded with curcumin / carboxybenzylpenicillin /mtx methotrexate / paclitaxel ptx/ DOX / cisplatin cddp/cpt camptothecin and other d
Uni app - one click access to user information
PHP starts OpenSSL and reports OpenSSL support=> disabled (install ext/openssl)
List 过滤、排序、校验等处理方法
Prophet
MySQL is required to sort in ascending order greater than or equal to the current time, and then in descending order less than the current time
Rs232/rs485 to 4G DTU uploading temperature and humidity sensor data based on Modbus protocol to remote TCP server
判断一串数字是否是快速排序某一次的结果
Istio安装与使用
[Fibonacci series]
App test_ Summary of test points
[interview question 17.04. missing numbers]
Google Gmail mailbox marks all unread messages as read at once
Link list of high frequency written interview question brushing summary (distribution explanation & code annotation)
[MySQL 45 -10] Lesson 10 how MySQL selects indexes
When the interviewer opens his mouth, he comes to compose. Is this the case now?
Common vocabulary of software testing English
[resolved] how to fix another update in progress WordPress upgrade error