Skip to content

Commit 356fd4e

Browse files
JavaScalaDeveloperJavaScalaDeveloper
authored andcommitted
删掉除了Java语言以外的代码
1 parent 8d65137 commit 356fd4e

File tree

3,095 files changed

+19889
-295149
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

3,095 files changed

+19889
-295149
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,5 @@
1313
/lcci/lcci.json
1414
/solution/__pycache__
1515
/solution/.env
16-
*.iml
16+
*.iml
17+
/out/

basic/sorting/BubbleSort/README.md

Lines changed: 5 additions & 169 deletions
Original file line numberDiff line numberDiff line change
@@ -42,195 +42,31 @@ public class BubbleSort {
4242
}
4343
```
4444

45-
### **JavaScript**
46-
47-
```js
48-
function bubbleSort(inputArr) {
49-
for (let i = inputArr.length - 1; i > 0; i--) {
50-
let hasChange = false;
51-
for (let j = 0; j < i; j++) {
52-
if (inputArr[j] > inputArr[j + 1]) {
53-
const temp = inputArr[j];
54-
inputArr[j] = inputArr[j + 1];
55-
inputArr[j + 1] = temp;
56-
hasChange = true;
57-
}
58-
}
5945

60-
if (!hasChange) {
61-
break;
62-
}
63-
}
6446

65-
return inputArr;
66-
}
6747

68-
const arr = [6, 3, 2, 1, 5];
69-
console.log(bubbleSort(arr));
70-
```
7148

72-
### **Go**
7349

74-
```go
75-
package main
7650

77-
import "fmt"
7851

79-
func bubbleSort(nums []int) {
80-
hasChange := true
81-
for i, n := 0, len(nums); i < n-1 && hasChange; i++ {
82-
hasChange = false
83-
for j := 0; j < n-i-1; j++ {
84-
if nums[j] > nums[j+1] {
85-
nums[j], nums[j+1] = nums[j+1], nums[j]
86-
hasChange = true
87-
}
88-
}
89-
}
90-
}
9152

92-
func main() {
93-
nums := []int{1, 2, 7, 9, 5, 8}
94-
bubbleSort(nums)
95-
fmt.Println(nums)
96-
}
97-
```
9853

99-
### **C++**
10054

101-
```cpp
102-
#include <iostream>
103-
#include <vector>
10455

105-
using namespace std;
10656

107-
void bubbleSort(vector<int>& arr) {
108-
int n = arr.size();
109-
for (int i = 0; i < n - 1; ++i) {
110-
bool change = false;
111-
for (int j = 0; j < n - i - 1; ++j) {
112-
if (arr[j] > arr[j + 1]) {
113-
swap(arr[j], arr[j + 1]);
114-
change = true;
115-
}
116-
}
117-
if (!change) break;
118-
}
119-
}
12057

121-
int main() {
122-
vector<int> arr = {9, 8, 7, 6, 5, 4, 3, 2, 1, 0};
123-
bubbleSort(arr);
124-
for (int v : arr) cout << v << " ";
125-
cout << endl;
126-
}
127-
```
12858

129-
### **Rust**
130-
131-
```rust
132-
fn bubble_sort(nums: &mut Vec<i32>) {
133-
let n = nums.len();
134-
for i in 0..n - 1 {
135-
for j in i..n {
136-
if nums[i] > nums[j] {
137-
let temp = nums[i];
138-
nums[i] = nums[j];
139-
nums[j] = temp;
140-
}
141-
}
142-
}
143-
}
14459

145-
fn main() {
146-
let mut nums = vec![1, 2, 7, 9, 5, 8];
147-
bubble_sort(&mut nums);
148-
println!("{:?}", nums);
149-
}
150-
```
15160

152-
### **C#**
153-
154-
```cs
155-
using static System.Console;
156-
namespace Pro;
157-
public class Program
158-
{
159-
public static void Main()
160-
{
161-
int[] test = new int[] { 56, 876, 34, 23, 45, 501, 2, 3, 4, 6, 5, 7, 8, 9, 11, 10, 12, 23, 34 };
162-
BubbleSortNums(test);
163-
foreach (var item in test)
164-
{
165-
WriteLine(item);
166-
}
167-
ReadLine();
168-
}
169-
public static void BubbleSortNums(int[] nums)
170-
{
171-
int numchange = 0;
172-
for (int initial = 0; initial < nums.Length - numchange; initial++)
173-
{
174-
WriteLine($"{initial} start ");
175-
// 记录此值 用于迭代开始位置
176-
bool changelog = false;
177-
for (int second_sortnum = initial; second_sortnum < nums.Length - 1; second_sortnum++)
178-
{
179-
if (nums[second_sortnum] > nums[second_sortnum + 1])
180-
{
181-
swap(ref nums[second_sortnum], ref nums[second_sortnum + 1]);
182-
if (!changelog)
183-
{
184-
// 记录转换的位置,让initial开始位置从转换位置前开始
185-
initial = ((second_sortnum - 2) > 0) ? (second_sortnum - 2) : -1;
186-
numchange += 1;
187-
}
188-
changelog = true;
189-
}
190-
}
191-
}
192-
}
193-
private static void swap(ref int compare_left, ref int compare_right)
194-
{
195-
int temp = compare_left;
196-
compare_left = compare_right;
197-
compare_right = temp;
198-
}
199-
}
200-
```
61+
62+
63+
20164

20265
### **Python3**
20366

204-
```python
205-
def bubbleSort(arr):
206-
n = len(arr)
207-
# Iterate over all array elements
208-
for i in range(n):
209-
# Last i elements are already in place
210-
for j in range(n - i - 1):
211-
if arr[j] > arr[j + 1]:
212-
arr[j], arr[j + 1] = arr[j + 1], arr[j]
213-
214-
215-
# 改进版本
216-
def bubbleSort(arr):
217-
n = len(arr)
218-
for i in range(n - 1):
219-
has_change = False
220-
for j in range(n - i - 1):
221-
if arr[j] > arr[j + 1]:
222-
arr[j], arr[j + 1] = arr[j + 1], arr[j]
223-
has_change = True
224-
if not has_change:
225-
break
226-
227-
228-
arr = [64, 34, 25, 12, 22, 11, 90]
229-
bubbleSort(arr)
230-
print(arr)
231-
```
23267

233-
<!-- tabs:end -->
68+
69+
23470

23571
## 算法分析
23672

basic/sorting/CountingSort/README.md

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -36,36 +36,11 @@ public static void sort(int[] nums, int min, int max) {
3636
}
3737
```
3838

39-
### **Go**
4039

41-
```go
42-
func CountingSort(nums []int, min, max int) {
43-
n := len(nums)
44-
k := max - min + 1
45-
c := make([]int, k)
46-
for _, v := range nums {
47-
c[v-min]++
48-
}
4940

50-
for i := 1; i < k; i++ {
51-
c[i] += c[i-1]
52-
}
5341

54-
r := make([]int, n)
55-
for i := n - 1; i >= 0; i-- {
56-
v := nums[i]
57-
a := c[v]
58-
r[a-1] = v + min
59-
c[v]--
60-
}
6142

62-
for i, v := range r {
63-
nums[i] = v
64-
}
65-
}
66-
```
6743

68-
<!-- tabs:end -->
6944

7045
## 算法分析
7146

0 commit comments

Comments
 (0)