New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

github.com/m-simeonov/go-data-structures

Package Overview
Dependencies
Alerts
File Explorer
Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github.com/m-simeonov/go-data-structures

  • v0.0.0-20210813144516-fc56f50fd054
  • Source
  • Go
  • Socket score

Version published
Created
Source

Data Structures

install package

go get github.com/m-simeonov/go-data-structures

LIFO Stack (Last In First Out)

Stack is a linear data structure which follows a particular order in which the operations are performed. The order is Last In First Out.

Init Stack
stack := stack.New()
Push Element
stack.Push("one")
Pop Element
val := stack.Pop()
Get Length
len := stack.GetLength()
Example LIFO Stack
lifoStack := stack.New()
// Push Element to LifoStack
lifoStack.Push("one")
lifoStack.Push("two")

fmt.Println(lifoStack.GetLength()) // will print `2`

element, err := lifoStack.Pop()
if err == nil {
    fmt.Println(element) // will print `two`
}

Linked List

A linked list is a linear data structure, in which the elements are not stored at contiguous memory locations. A linked list consists of nodes where each node contains a data field and a reference(link) to the next node in the list

Init linked list
linkedList := list.New()
Add Value to linked list
linkedList.Add("one")
Delete node
linkedList.Delete(head)
Convert linked list to slice
data := linkedList.ToSlice()
Get Head
tail := linkedList.GetHead()
Get Tail
tail := linkedList.GetTail()
Get Length
len := linkedList.GetLength()
Example linked list
linkedList := list.New()
linkedList.Add("one")
linkedList.Add("two")
linkedList.Add("three")

data := linkedList.ToSlice()
fmt.Println(data) // will print [one two three]

len := linkedList.GetLength()
fmt.Println(len) // will print 3

head := linkedList.GetHead()
fmt.Println(head.Data) // will print `one`
linkedList.Delete(head)

data = linkedList.ToSlice()
fmt.Println(data) // will print [two three]

FAQs

Package last updated on 13 Aug 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc