ll

command module
v0.6.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 27, 2025 License: MIT Imports: 3 Imported by: 0

README

LinkedList Library

This is a LinkedList Library, a Go-based implementation of both singly linked lists and doubly linked lists.


Features

Singly Linked List
  • Basic Operations: Append, Prepend, Delete, Insert, and more.
  • Traversal: Print elements from head to tail.
  • Conversions: Convert to/from slices and arrays.
  • Search: Find the index of a value.
  • Sorting: Sort elements (supports int, string, and float64).
  • Reversal: Reverse the order of elements.
  • Advanced Features:
    • Detect cycles using Floyd's Cycle-Finding Algorithm.
    • Get the middle element of the list.
    • Remove duplicates.
    • Merge with another list.
Doubly Linked List
  • Bidirectional Traversal: Print elements from head to tail or tail to head.
  • Basic Operations: Append, Prepend, Delete, Insert, and more.
  • Conversions: Convert to/from slices and arrays.
  • Search: Find the index of a value.
  • Sorting: Sort elements (supports int, string, and float64).
  • Reversal: Reverse the order of elements.
  • Advanced Features:
    • Validate the integrity of the list structure.
    • Remove duplicates.
    • Merge with another list.

Installation

To use this library, you need to have Go installed on your system. Clone the repository and initialize the module:

git clone https://github.com/JustMrNone/LinkedList.git
cd LinkedList
go mod tidy

Usage

Singly Linked List Example
package main

import (
    "fmt"
    "github.com/JustMrNone/LinkedList/singly"
)

func main() {
    list := singly.NewSinglyLinkedList()

    // Basic operations
    list.Append(1)
    list.Append(2)
    list.Prepend(0)
    list.Print() // Output: 0 -> 1 -> 2

    // Advanced operations
    list.Sort()
    list.Print() // Output: 0 -> 1 -> 2 (sorted)
}
Doubly Linked List Example
package main

import (
    "fmt"
    "github.com/JustMrNone/LinkedList/doubly"
)

func main() {
    list := doubly.NewDoublyLinkedList()

    // Basic operations
    list.Append(1)
    list.Append(2)
    list.Prepend(0)
    list.Print() // Output: 0 <-> 1 <-> 2

    // Print in reverse
    list.PrintReverse() // Output: 2 <-> 1 <-> 0
}

API Documentation

Singly Linked List
Methods
  • NewSinglyLinkedList() *LinkedList: Creates a new singly linked list.
  • Append(value any): Adds a value to the end of the list.
  • Prepend(value any): Adds a value to the beginning of the list.
  • Delete(value any): Removes the first occurrence of a value.
  • Insert(value any, index int): Inserts a value at the specified index.
  • Search(value any) int: Returns the index of the first occurrence of a value.
  • Sort(): Sorts the list (supports int, string, and float64).
  • Reverse(): Reverses the list.
  • GetMiddle() (any, error): Returns the middle element of the list.
Doubly Linked List
Methods
  • NewDoublyLinkedList() *LinkedList: Creates a new doubly linked list.
  • Append(value any): Adds a value to the end of the list.
  • Prepend(value any): Adds a value to the beginning of the list.
  • Delete(value any): Removes the first occurrence of a value.
  • Insert(value any, index int): Inserts a value at the specified index.
  • Search(value any) (int, error): Returns the index of the first occurrence of a value.
  • Sort(): Sorts the list (supports int, string, and float64).
  • Reverse(): Reverses the list.
  • PrintReverse(): Prints the list in reverse order.

Testing

This library includes comprehensive test cases for both singly and doubly linked lists. To run the tests, use:

go test -v

To run benchmarks:

go test -bench=.

Acknowledgments

Special thanks to the Go community for their excellent resources.


Enjoy!

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis
Package doubly implements a doubly linked list data structure.
Package doubly implements a doubly linked list data structure.
Package singly implements a singly linked list data structure.
Package singly implements a singly linked list data structure.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL