Add Swift language blocks to the docs.

This commit is contained in:
Yudong Jin
2023-01-08 19:41:05 +08:00
parent 3ba37dba3a
commit 73e3452838
22 changed files with 414 additions and 70 deletions
@@ -15,12 +15,12 @@ int *randomNumbers(int n) {
nums[i] = i + 1;
}
// 随机打乱数组元素
for (int i = n - 1; i > 0; i--) {
int j = rand() % (i + 1);
int temp = nums[i];
nums[i] = nums[j];
nums[j] = temp;
}
for (int i = n - 1; i > 0; i--) {
int j = rand() % (i + 1);
int temp = nums[i];
nums[i] = nums[j];
nums[j] = temp;
}
return nums;
}
+2 -2
View File
@@ -11,8 +11,8 @@
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.4.0" />
<PackageReference Include="NUnit" Version="3.13.3" />
<PackageReference Include="NUnit3TestAdapter" Version="4.0.0" />
<PackageReference Include="coverlet.collector" Version="3.1.0" />
<PackageReference Include="NUnit3TestAdapter" Version="4.0.0" />
<PackageReference Include="coverlet.collector" Version="3.1.0" />
</ItemGroup>
</Project>
@@ -4,7 +4,7 @@
* Author: nuomi1 (nuomi1@qq.com)
*/
//
/* */
func randomAccess(nums: [Int]) -> Int {
// [0, nums.count)
let randomIndex = nums.indices.randomElement()!
@@ -13,7 +13,7 @@ func randomAccess(nums: [Int]) -> Int {
return randomNum
}
//
/* */
func extend(nums: [Int], enlarge: Int) -> [Int] {
//
var res = Array(repeating: 0, count: nums.count + enlarge)
@@ -25,7 +25,7 @@ func extend(nums: [Int], enlarge: Int) -> [Int] {
return res
}
// index num
/* index num */
func insert(nums: inout [Int], num: Int, index: Int) {
// index
for i in sequence(first: nums.count - 1, next: { $0 > index + 1 ? $0 - 1 : nil }) {
@@ -35,7 +35,7 @@ func insert(nums: inout [Int], num: Int, index: Int) {
nums[index] = num
}
// index
/* index */
func remove(nums: inout [Int], index: Int) {
let count = nums.count
// index
@@ -44,7 +44,7 @@ func remove(nums: inout [Int], index: Int) {
}
}
//
/* */
func traverse(nums: [Int]) {
var count = 0
//
@@ -57,7 +57,7 @@ func traverse(nums: [Int]) {
}
}
//
/* */
func find(nums: [Int], target: Int) -> Int {
for i in nums.indices {
if nums[i] == target {