https://github.com/lovesaroha/lstack
This is a generalized stack package with clean and transparent API for the Go language.
https://github.com/lovesaroha/lstack
Last synced: 11 months ago
JSON representation
This is a generalized stack package with clean and transparent API for the Go language.
- Host: GitHub
- URL: https://github.com/lovesaroha/lstack
- Owner: lovesaroha
- License: gpl-3.0
- Created: 2021-09-15T09:40:40.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2021-09-26T12:23:36.000Z (over 4 years ago)
- Last Synced: 2025-01-12T19:23:11.821Z (12 months ago)
- Language: Go
- Size: 13.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# lstack
This is a generalized stack package with clean and transparent API for the Go language.
## Features
- Lightweight and Fast.
- Native Go implementation.
- Support all data types.
## Requirements
- Go 1.9 or higher. We aim to support the 3 latest versions of Go.
## Installation
Simple install the package to your [$GOPATH](https://github.com/golang/go/wiki/GOPATH "GOPATH") with the [go tool](https://golang.org/cmd/go/ "go command") from shell:
```bash
go get -u github.com/lovesaroha/lstack
```
Make sure [Git is installed](https://git-scm.com/downloads) on your machine and in your system's `PATH`.
## Usage
### Create Stack
```Golang
// Create a stack.
stack := lstack.Create()
// Add values in stack.
stack.Push(2)
stack.Push(4)
stack.Push(6)
stack.Push("love")
// Remove value from stack and return value.
stack.Pop()
// Print values in stack.
stack.Print()
```
### Add Multiple Values
```Golang
// Create a stack.
stack := lstack.Create()
// Add values in stack.
stack.PushValues([]interface{}{1,2,3,4,5,6,7,8,9})
// Remove value from stack and return value.
stack.Pop()
// Print values in stack.
stack.Print()
```
### Custom Data Type
```Golang
type user struct {
name string
}
// Create a stack.
stack := lstack.Create()
// Add values in stack.
stack.Push(user{name: "love"})
stack.Push(user{name: "joe"})
stack.Push(user{name: "doe"})
// Remove value from stack and return value.
stack.Pop()
// Print values in stack.
stack.Print()
```
### Pop Values With Specific Data Type
```Golang
// Create a stack.
stack := lstack.Create()
// Add values in stack.
stack.Push(2)
stack.Push(4)
stack.Push(6)
stack.Push("love")
// Remove value from stack and return string value ("love").
stack.PopString()
// Remove value from stack and return int value (6).
stack.PopInt()
// Remove value from stack and return float64 value (4.00).
stack.PopFloat64()
// Print values in stack.
stack.Print()