搜索插件、代码仓与 APP 分类

插件详情v0.2.2

stack

一个用于栈数据结构的包。具有 push、pop、size、length 和 top 功能。

AndroidiOSWebmacOSWindowsLinux
近 30 天下载
2万
喜欢数
38
Pub 分数
160

安装插件

flutter pub add stack

插件介绍

基于插件公开信息、社区数据与项目使用情况整理的选型参考。

该 stack 包在 Dart 中提供了简单且高效的栈数据结构实现,支持 push、pop、size、length 和 top 等核心操作。专为需要轻量级、可靠栈来管理后进先出(LIFO)数据工作流的开发者设计。该包与平台无关,可在 Android、iOS、Web、macOS、Windows 和 Linux 上无缝运行。适用于算法任务、表达式求值或管理函数调用上下文,可通过 pub.dev 轻松集成到 Flutter 和 Dart 项目中。

适合场景

  • 实现撤销/重做功能
  • 解析表达式和语法验证
  • 管理函数调用堆栈
  • 处理嵌套结构
  • 回溯算法

主要特点

  • 推送和弹出操作
  • 访问顶层元素
  • 尺寸和长度属性
  • 跨平台兼容性
  • 最小内存占用

适合对象

  • 需要后进先出数据处理的 Dart 开发人员
  • 算法实现
  • 教育项目
  • 使用后进先出(LIFO)逻辑进行状态管理
  • 轻量级实用工具需求

使用建议

  • 不适用于FIFO操作
  • 仅限基本栈行为
  • 无内置线程安全
  • 不支持自定义比较器
  • 需要手动处理空栈访问的错误

原始 README

以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。

dart_stack

A dart package for stack datastructure

pub codecov CircleCI

Usage

Add dev dependency to your pubspec.yaml:

dev_dependencies:
  stack: ^0.0.1

Run pub get to install.

How it works

Import

import 'package:stack/stack.dart';

Example

// Initialize
Stack<String> stack = Stack();
// Push
stack.push('abc');
// See the top
stack.top();
// Pop the top
stack.pop();
// Check for empty
stack.isEmpty;
// Check for non-enpty
stack.isNotEmpty;
// see if the stack has a certain object
stack.contains("abc");
// print the complete stack
stack.print();
// get size of current stack
stack.size() || var s = stack.size()

Exceptions

Trying to use top() or pop() on an empty stack throws IllegalOperationException. use size(), isEmpty, or isNotEmpty to check before using these operations.

Feel free to file feature requests and bug reports at the issue tracker.

所属分类

源码仓库

使用此插件的项目