Refine some details and coding style for Rust codes (#344)

* Refine some details and coding style for Rust codes

* Update coding style for Rust codes

* Update time_complexity.rs

* Update array.rs

* Update leetcode_two_sum.rs

* Update hash_map.rs

* Update file headers

* Update coding style for Rust codes and Zig codes

* Update coding style for Rust codes and Zig codes

---------

Co-authored-by: Yudong Jin <krahets@163.com>
This commit is contained in:
sjinzh
2023-02-09 00:25:01 +08:00
committed by GitHub
parent 6dc21691ed
commit e65c7bd478
20 changed files with 189 additions and 177 deletions

View File

@@ -31,13 +31,13 @@ pub fn ArrayStack(comptime T: type) type {
}
// 判断栈是否为空
pub fn empty(self: *Self) bool {
pub fn isEmpty(self: *Self) bool {
return self.size() == 0;
}
// 访问栈顶元素
pub fn top(self: *Self) T {
if (self.size() == 0) @panic("栈为空");
pub fn peek(self: *Self) T {
if (self.isEmpty()) @panic("栈为空");
return self.stack.?.items[self.size() - 1];
}
@@ -77,7 +77,7 @@ pub fn main() !void {
inc.PrintUtil.printList(i32, stack.toList());
// 访问栈顶元素
var peek = stack.top();
var peek = stack.peek();
std.debug.print("\n栈顶元素 peek = {}", .{peek});
// 元素出栈
@@ -90,7 +90,7 @@ pub fn main() !void {
std.debug.print("\n栈的长度 size = {}", .{size});
// 判断栈是否为空
var is_empty = stack.empty();
var is_empty = stack.isEmpty();
std.debug.print("\n栈是否为空 = {}", .{is_empty});
_ = try std.io.getStdIn().reader().readByte();