XU XUv0.8.8
EN

API

#container/heap

import: #container/heap

counts: 6 函数, 6 方法, 2 类型, 0 常量, 0 方法集

IntHeap / StrHeap 最小堆。

struct IntHeap

XuAPI
pub struct IntHeap {
    pub a []int
    pub n int
}

用途

公开结构体 `IntHeap`。

参数

a []int
字段([]int)
n int
数量、长度或上限

struct StrHeap

XuAPI
pub struct StrHeap {
    pub a []string
    pub n int
}

用途

公开结构体 `StrHeap`。

参数

a []string
字段([]string)
n int
数量、长度或上限

new_ints

XuAPI
pub fn new_ints() IntHeap

用途

构造 ints。

参数

无

返回

IntHeap — 该类型的值

new_strs

XuAPI
pub fn new_strs() StrHeap

用途

构造 strs。

参数

无

返回

StrHeap — 该类型的值

from_ints

XuAPI
pub fn from_ints(xs []int) IntHeap

用途

从 ints 构造。

参数

xs []int
要处理的切片([]int)

返回

IntHeap — 该类型的值

from_strs

XuAPI
pub fn from_strs(xs []string) StrHeap

用途

从 strs 构造。

参数

xs []string
要处理的切片([]string)

返回

StrHeap — 该类型的值

len_ints

XuAPI
pub fn len_ints(h &IntHeap) int

用途

长度int 切片。

参数

h &IntHeap
高度或句柄(借用,调用方仍持有;类型 &IntHeap)

返回

int — 该类型的值

len_strs

XuAPI
pub fn len_strs(h &StrHeap) int

用途

长度strs。

参数

h &StrHeap
高度或句柄(借用,调用方仍持有;类型 &StrHeap)

返回

int — 该类型的值

(&mut StrHeap) init

XuAPI
pub fn (h &mut StrHeap) init()

用途

在 `&mut StrHeap` 上调用 `init`。

参数

h &mut StrHeap
接收者 &mut StrHeap(可变借用)

(&mut IntHeap) init

XuAPI
pub fn (h &mut IntHeap) init()

用途

在 `&mut IntHeap` 上调用 `init`。

参数

h &mut IntHeap
接收者 &mut IntHeap(可变借用)

(&mut IntHeap) push

XuAPI
pub fn (h &mut IntHeap) push(x int)

用途

`&mut IntHeap` 上的方法:压入。

参数

h &mut IntHeap
接收者 &mut IntHeap(可变借用)
x int
值(int)

(&mut IntHeap) pop

XuAPI
pub fn (h &mut IntHeap) pop() int

用途

`&mut IntHeap` 上的方法:弹出。失败时 throw。

参数

h &mut IntHeap
接收者 &mut IntHeap(可变借用)

返回

int — 该类型的值

(&mut StrHeap) push

XuAPI
pub fn (h &mut StrHeap) push(x string)

用途

`&mut StrHeap` 上的方法:压入。

参数

h &mut StrHeap
接收者 &mut StrHeap(可变借用)
x string
值(string)

(&mut StrHeap) pop

XuAPI
pub fn (h &mut StrHeap) pop() string

用途

`&mut StrHeap` 上的方法:弹出。失败时 throw。

参数

h &mut StrHeap
接收者 &mut StrHeap(可变借用)

返回

string — 结果字符串