|
|
|
@ -6,7 +6,6 @@ const std = @import("std");
|
|
|
|
|
const inc = @import("include");
|
|
|
|
|
|
|
|
|
|
// 基于数组实现的栈
|
|
|
|
|
// 编译期泛型
|
|
|
|
|
pub fn ArrayStack(comptime T: type) type {
|
|
|
|
|
return struct {
|
|
|
|
|
const Self = @This();
|
|
|
|
@ -78,11 +77,11 @@ pub fn main() !void {
|
|
|
|
|
inc.PrintUtil.printList(i32, stack.toList());
|
|
|
|
|
|
|
|
|
|
// 访问栈顶元素
|
|
|
|
|
var top = stack.top();
|
|
|
|
|
std.debug.print("\n栈顶元素 top = {}", .{top});
|
|
|
|
|
var peek = stack.top();
|
|
|
|
|
std.debug.print("\n栈顶元素 peek = {}", .{peek});
|
|
|
|
|
|
|
|
|
|
// 元素出栈
|
|
|
|
|
top = stack.pop();
|
|
|
|
|
var top = stack.pop();
|
|
|
|
|
std.debug.print("\n出栈元素 pop = {},出栈后 stack = ", .{top});
|
|
|
|
|
inc.PrintUtil.printList(i32, stack.toList());
|
|
|
|
|
|
|
|
|
@ -91,9 +90,8 @@ pub fn main() !void {
|
|
|
|
|
std.debug.print("\n栈的长度 size = {}", .{size});
|
|
|
|
|
|
|
|
|
|
// 判断栈是否为空
|
|
|
|
|
var empty = stack.empty();
|
|
|
|
|
std.debug.print("\n栈是否为空 = {}", .{empty});
|
|
|
|
|
var is_empty = stack.empty();
|
|
|
|
|
std.debug.print("\n栈是否为空 = {}", .{is_empty});
|
|
|
|
|
|
|
|
|
|
const getchar = try std.io.getStdIn().reader().readByte();
|
|
|
|
|
_ = getchar;
|
|
|
|
|
_ = try std.io.getStdIn().reader().readByte();
|
|
|
|
|
}
|
|
|
|
|