Compare commits
48 Commits
feature/qu
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 41a169f2ea | |||
| 2207c987a9 | |||
| afddab0584 | |||
| 47af4aca14 | |||
| a303098ec8 | |||
| 0469b97bd5 | |||
| 7573374102 | |||
| 8d7894ef9a | |||
| b7db13bd32 | |||
| 91312268aa | |||
| d4a81d36de | |||
| 2b2e5da541 | |||
| e768a3975b | |||
| 5ac3791a05 | |||
| ac633048b4 | |||
| a82c158c5f | |||
| 858b205d5d | |||
| b793db559e | |||
| 8e523bf976 | |||
| aca3b6ecb5 | |||
| 6acf5a68a4 | |||
| 5fade46e46 | |||
| c51d6cb241 | |||
| 0cd09e473c | |||
| 33b0426313 | |||
| aa0f709ca9 | |||
| 1dfdc26bab | |||
| b3bad42f62 | |||
| 3c28b9be57 | |||
| bdf7bc0684 | |||
| 401374bed8 | |||
| f0c139694a | |||
| 51a237e275 | |||
| c1c5f53c86 | |||
| 74e8a13585 | |||
| 7e92fe47cc | |||
| dc04fd9b84 | |||
| 0de640edd8 | |||
| c185db7fd8 | |||
| af94031e94 | |||
| 62853dcbdd | |||
| 3c9ba2ef8f | |||
| d15d2827ff | |||
| 8eb51e4202 | |||
| 8d552fef41 | |||
| e496310532 | |||
| 8101eb52bd | |||
| 942ac51236 |
@@ -1,17 +0,0 @@
|
|||||||
name: Code Review
|
|
||||||
on:
|
|
||||||
issue_comment:
|
|
||||||
types: [created, edited]
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
code-review:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- name: OpenAI Code Review
|
|
||||||
uses: bhavik/gitea-code-review-action@v0.1
|
|
||||||
with:
|
|
||||||
PROGRAMMING_LANGUAGE: 'JavaScript'
|
|
||||||
OPENAI_TOKEN: ${{ secrets.OPENAI_TOKEN }}
|
|
||||||
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
|
|
||||||
FULL_REVIEW_COMMENT: 'openai'
|
|
||||||
REVIEW_COMMENT_PREFIX: 'openai:'
|
|
||||||
23
.gitea/workflows/code-review.yml
Normal file
23
.gitea/workflows/code-review.yml
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
name: AI Code Review (on comment)
|
||||||
|
|
||||||
|
on:
|
||||||
|
issue_comment:
|
||||||
|
types: [created, edited]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
code-review:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
if: github.event.issue.pull_request && (startsWith(github.event.comment.body, 'openai') || github.event.comment.body == 'openai')
|
||||||
|
|
||||||
|
steps:
|
||||||
|
|
||||||
|
- name: Comment on PR
|
||||||
|
uses: https://devstar.cn/beppeb/pr-comment-action@main
|
||||||
|
with:
|
||||||
|
body: "✅ 构建完成!"
|
||||||
|
token: e61260b1d4b4c981e6f91913fa98933005271f89
|
||||||
|
server: https://devstar.cn
|
||||||
|
owner: beppeb
|
||||||
|
repo: demo-workflow-repo
|
||||||
|
pr_number: 8
|
||||||
|
|
||||||
22
.gitea/workflows/test1.yml
Normal file
22
.gitea/workflows/test1.yml
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
name: ai-reviews
|
||||||
|
|
||||||
|
on:
|
||||||
|
pull_request:
|
||||||
|
types: [created, edited]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
review:
|
||||||
|
name: Review PR
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Checkout code
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
fetch-depth: 0
|
||||||
|
- name: Review code
|
||||||
|
uses: kekxv/AiReviewPR@v0.0.5
|
||||||
|
with:
|
||||||
|
model: 'deepseek-r1:8b'
|
||||||
|
host: 'http://127.0.0.1:11434'
|
||||||
|
REVIEW_PULL_REQUEST: false
|
||||||
176
js/quicksort.js
176
js/quicksort.js
@@ -1,176 +0,0 @@
|
|||||||
/**
|
|
||||||
* 快速排序算法实现
|
|
||||||
* 时间复杂度: 平均 O(n log n), 最坏 O(n²)
|
|
||||||
* 空间复杂度: O(log n)
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 快速排序主函数
|
|
||||||
* @param {Array} arr - 要排序的数组
|
|
||||||
* @returns {Array} - 排序后的数组
|
|
||||||
*/
|
|
||||||
function quickSort(arr) {
|
|
||||||
// 如果数组长度小于等于1,直接返回
|
|
||||||
if (arr.length <= 1) {
|
|
||||||
return arr;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 选择基准值(这里选择最后一个元素)
|
|
||||||
const pivot = arr[arr.length - 1];
|
|
||||||
const left = [];
|
|
||||||
const right = [];
|
|
||||||
|
|
||||||
// 将数组分成两部分
|
|
||||||
for (let i = 0; i < arr.length - 1; i++) {
|
|
||||||
if (arr[i] <= pivot) {
|
|
||||||
left.push(arr[i]);
|
|
||||||
} else {
|
|
||||||
right.push(arr[i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 递归排序左右两部分,并合并结果
|
|
||||||
return [...quickSort(left), pivot, ...quickSort(right)];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 原地快速排序(优化版本,节省空间)
|
|
||||||
* @param {Array} arr - 要排序的数组
|
|
||||||
* @param {number} low - 起始索引
|
|
||||||
* @param {number} high - 结束索引
|
|
||||||
*/
|
|
||||||
function quickSortInPlace(arr, low = 0, high = arr.length - 1) {
|
|
||||||
if (low < high) {
|
|
||||||
const pivotIndex = partition(arr, low, high);
|
|
||||||
quickSortInPlace(arr, low, pivotIndex - 1);
|
|
||||||
quickSortInPlace(arr, pivotIndex + 1, high);
|
|
||||||
}
|
|
||||||
return arr;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 分区函数
|
|
||||||
* @param {Array} arr - 数组
|
|
||||||
* @param {number} low - 起始索引
|
|
||||||
* @param {number} high - 结束索引
|
|
||||||
* @returns {number} - 基准值的最终位置
|
|
||||||
*/
|
|
||||||
function partition(arr, low, high) {
|
|
||||||
// 选择最后一个元素作为基准值
|
|
||||||
const pivot = arr[high];
|
|
||||||
let i = low - 1; // 小于基准值的元素的最后位置
|
|
||||||
|
|
||||||
for (let j = low; j < high; j++) {
|
|
||||||
// 如果当前元素小于等于基准值
|
|
||||||
if (arr[j] <= pivot) {
|
|
||||||
i++;
|
|
||||||
// 交换元素
|
|
||||||
[arr[i], arr[j]] = [arr[j], arr[i]];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 将基准值放到正确的位置
|
|
||||||
[arr[i + 1], arr[high]] = [arr[high], arr[i + 1]];
|
|
||||||
return i + 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 三路快速排序(处理重复元素较多的数组)
|
|
||||||
* @param {Array} arr - 要排序的数组
|
|
||||||
* @param {number} low - 起始索引
|
|
||||||
* @param {number} high - 结束索引
|
|
||||||
*/
|
|
||||||
function quickSortThreeWay(arr, low = 0, high = arr.length - 1) {
|
|
||||||
if (low < high) {
|
|
||||||
const [lt, gt] = partitionThreeWay(arr, low, high);
|
|
||||||
quickSortThreeWay(arr, low, lt - 1);
|
|
||||||
quickSortThreeWay(arr, gt + 1, high);
|
|
||||||
}
|
|
||||||
return arr;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 三路分区函数
|
|
||||||
* @param {Array} arr - 数组
|
|
||||||
* @param {number} low - 起始索引
|
|
||||||
* @param {number} high - 结束索引
|
|
||||||
* @returns {Array} - [lt, gt] 小于和大于基准值的边界
|
|
||||||
*/
|
|
||||||
function partitionThreeWay(arr, low, high) {
|
|
||||||
const pivot = arr[low];
|
|
||||||
let lt = low; // 小于基准值的右边界
|
|
||||||
let gt = high; // 大于基准值的左边界
|
|
||||||
let i = low + 1; // 当前扫描位置
|
|
||||||
|
|
||||||
while (i <= gt) {
|
|
||||||
if (arr[i] < pivot) {
|
|
||||||
[arr[lt], arr[i]] = [arr[i], arr[lt]];
|
|
||||||
lt++;
|
|
||||||
i++;
|
|
||||||
} else if (arr[i] > pivot) {
|
|
||||||
[arr[gt], arr[i]] = [arr[i], arr[gt]];
|
|
||||||
gt--;
|
|
||||||
} else {
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return [lt, gt];
|
|
||||||
}
|
|
||||||
|
|
||||||
// 测试函数
|
|
||||||
function testQuickSort() {
|
|
||||||
console.log("=== 快速排序算法测试 ===");
|
|
||||||
|
|
||||||
// 测试数据
|
|
||||||
const testCases = [
|
|
||||||
[64, 34, 25, 12, 22, 11, 90],
|
|
||||||
[5, 2, 4, 6, 1, 3],
|
|
||||||
[1],
|
|
||||||
[],
|
|
||||||
[3, 3, 3, 3, 3],
|
|
||||||
[9, 8, 7, 6, 5, 4, 3, 2, 1],
|
|
||||||
[1, 2, 3, 4, 5, 6, 7, 8, 9]
|
|
||||||
];
|
|
||||||
|
|
||||||
testCases.forEach((testCase, index) => {
|
|
||||||
console.log(`\n测试用例 ${index + 1}:`);
|
|
||||||
console.log(`原始数组: [${testCase}]`);
|
|
||||||
|
|
||||||
// 测试标准快速排序
|
|
||||||
const sorted1 = quickSort([...testCase]);
|
|
||||||
console.log(`标准快排: [${sorted1}]`);
|
|
||||||
|
|
||||||
// 测试原地快速排序
|
|
||||||
const arr2 = [...testCase];
|
|
||||||
quickSortInPlace(arr2);
|
|
||||||
console.log(`原地快排: [${arr2}]`);
|
|
||||||
|
|
||||||
// 测试三路快速排序
|
|
||||||
const arr3 = [...testCase];
|
|
||||||
quickSortThreeWay(arr3);
|
|
||||||
console.log(`三路快排: [${arr3}]`);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// 导出函数供其他模块使用
|
|
||||||
if (typeof module !== 'undefined' && module.exports) {
|
|
||||||
module.exports = {
|
|
||||||
quickSort,
|
|
||||||
quickSortInPlace,
|
|
||||||
quickSortThreeWay,
|
|
||||||
partition,
|
|
||||||
partitionThreeWay
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
// 如果直接在浏览器中运行,执行测试
|
|
||||||
if (typeof window !== 'undefined') {
|
|
||||||
// 将函数添加到全局作用域
|
|
||||||
window.quickSort = quickSort;
|
|
||||||
window.quickSortInPlace = quickSortInPlace;
|
|
||||||
window.quickSortThreeWay = quickSortThreeWay;
|
|
||||||
|
|
||||||
// 自动运行测试
|
|
||||||
testQuickSort();
|
|
||||||
}
|
|
||||||
14
quicksort.py
14
quicksort.py
@@ -1,14 +0,0 @@
|
|||||||
def quick_sort(arr):
|
|
||||||
if len(arr) <= 1:
|
|
||||||
return arr
|
|
||||||
pivot = arr[len(arr) // 2] # 选取中间元素作为基准
|
|
||||||
left = [x for x in arr if x < pivot]
|
|
||||||
middle = [x for x in arr if x == pivot]
|
|
||||||
right = [x for x in arr if x > pivot]
|
|
||||||
return quick_sort(left) + middle + quick_sort(right)
|
|
||||||
|
|
||||||
|
|
||||||
# 示例
|
|
||||||
nums = [3, 6, 8, 10, 1, 2, 1]
|
|
||||||
print("排序前:", nums)
|
|
||||||
print("排序后:", quick_sort(nums))
|
|
||||||
Reference in New Issue
Block a user