- Swift_集合 let inde = numbers.part
- Swift_集合 let inde = arr.firstInd
- Swift_集合 let inde = arr.firstInd
- Swift_集合 let shuffledArr = numbe
- 8.集合类型(CollectionType)
- Swift_集合 let arrSub = arr.prefix
- Swift_集合 ` let arrSub = arr.pref
- Swift_集合 let element = arr.`remo
- Swift_集合 let arrSub = arr.`dro
- Swift_集合 ` let arrSub = arr.suff
对集合的元素进行重新排序(改变原数组),不满足给定条件的在前面,满足的在后面,返回索引' p '
/// 对集合的元素进行重新排序(改变原数组),不满足给定条件的在前面,满足的在后面,返回索引' p '。
///
/// 在对一个集合进行分区之后,存在一个主索引' p ',其中' p '之前的所有元素都不满足给定条件' ,' p '及' p '之后的所有元素都满足'。
///
/// 在下面的示例中,通过匹配给定条件(大于30的元素)对数字数组进行分区。
///
///
/// - Returns: 返回重新排序后的 ' p ' 索引。如果集合中没有元素匹配' 给定条件 ',则返回的索引等于集合的' endIndex '。
///
/// - Complexity: O(*n*), 集合的长度.
@inlinable public mutating func partition(by belongsInSecondPartition: (Element) throws -> Bool) rethrows -> Int
var numbers = [30, 40, 20, 30, 30, 60, 10]
let p = numbers.partition(by: { $0 > 30 })
print(p) // 5
let first = numbers[..<p]
print(first) // [30, 10, 20, 30, 30]
let second = numbers[p...]
print(second) // [60, 40]
print(numbers) // [30, 10, 20, 30, 30, 60, 40]
网友评论