Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

github.com/matej-chmel/go-linked-list

Package Overview
Dependencies
Alerts
File Explorer
Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github.com/matej-chmel/go-linked-list

  • v1.0.3
  • Source
  • Go
  • Socket score

Version published
Created
Source

Go Linked List

Generic library for singly and doubly linked lists.

Installation

go get github.com/Matej-Chmel/go-linked-list@v1.0.3

Features

  • Easy to use
  • Methods for accessing nodes by index and direction
  • Customizable conversion to a string

Example

package main

import (
	"fmt"

	lk "github.com/Matej-Chmel/go-linked-list"
)

func main() {
	// Easy construction
	singleHead := lk.CreateSinglyLinkedList(1, 2, 3)
	doubleHead := lk.CreateDoublyLinkedList[int8](10, 20, 30)

	// Conversion to string
	fmt.Println(singleHead)
	fmt.Println(doubleHead)

	node := singleHead
	sum := 0

	for node != nil {
		// Each node has Next and Val fields
		sum += node.Val
		node = node.Next
	}

	fmt.Println("Sum:", sum)

	// Doubly linked list can be iterated backwards
	current := doubleHead.GetLast()
	total := int8(0)

	for current != nil {
		total += current.Val
		current = current.Prev
	}

	fmt.Println("Total:", total)

	// Conversion to string can be customized
	symbols := lk.NewFormatSymbols(true)
	symbols.Start = "("
	symbols.Sep = ", "
	symbols.End = ")"

	fmt.Println(singleHead.Format(symbols))
}

Output

[1 > 2 > 3]
[10 <> 20 <> 30]
Sum: 6
Total: 60
(1, 2, 3)

FAQs

Package last updated on 28 Jul 2024

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