GithubHelp home page GithubHelp logo

farischt / ds Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 74 KB

Implementation of various data structures in go

License: MIT License

Go 99.94% Shell 0.06%
algorithms algorithms-and-data-structures algorithms-datastructures binary-search-tree binary-tree data-structures go golang linked-list queue stack tree graphs

ds's Introduction

ds

This project identifies the most commonly used data structures in software engineering. It is an open source project created by @Farischt

This project is also a go package via the following command :

go get github.com/farischt/ds

Packages

The project currently contains 6 different packages, one for each implemented data structure.

Here is a list of the different packages :

  • ds/queue for queues.
  • ds/stack for stacks.
  • ds/linked_list for linked lists.
  • ds/tree for trees.
  • ds/graph for binary graphs.
  • ds/heap for heaps.

ds/tree and ds/linked_list have each a separated Node structure.

How to use the different data structures

Queue

In order to create a queue:

    import (
        "github.com/farischt/ds/queue"
    )

    func main() {
        capacity := 1
        q := queue.New[int](capacity)
        // You can now use any method implementend in IQueue as seen in docs.
    }

Stack

In order to create a stack:

    import (
        "github.com/farischt/ds/stack"
    )

    func main() {
        capacity := 1
        s := stack.New[int](capacity)
        // You can now use any method implementend in IStack as seen in docs.
    }

Linked list

In order to create a linked list:

    import (
        "github.com/farischt/ds/linked_list"
    )

    func main() {
        l := ll.New[int]()
        // You can now use any method implementend in ILinkedList as seen in docs.
    }

Binary search tree

In order to create a binary search tree:

    import (
        "github.com/farischt/ds/tree"
    )

    func main() {
        rootData := 10
        root := tree.NewNode(rootData)
        l := tree.New(root)
        // You can now use any method implementend in IBinarySearchTree as seen in docs.
    }

Graph

In order to create a graph:

    import (
        "github.com/farischt/ds/graph"
    )

    func main() {
        g := graph.New[int]()
        // You can now use any method implementend in IGraph as seen in docs.

        // Before adding any edge, make sure to create nodes.
        src := 10
        dst := 20
        g.Add(src)
        g.Add(dst)
        g.AddUndirectedEdge(src, dst)
    }

Heap

In order to create a heap:

    import (
        "github.com/farischt/ds/heap"
    )

    func main() {
        minHeap := heap.New[int](heap.MinHeap)
        maxHeap := heap.New[int](heap.MaxHeap)
        // You can now use any method implementend in IGraph as seen in docs.

        // In some case a heap could only contain a native number type (int, uint...).
        data := 10 // This is the value used to compute the heap.
        minHeap.Push(data, nil)

        // On another hand, a heap could be use to store more than just a number. For example, in the diksjtra algorithm, we use a heap to store the value of a node and the current distance.
        node := 10 // This is the value used to compute the heap.
        distance := 30 // It could be any data type.
        minHeap.Push(node, distance)


        // If you pop the top element it will return an pointer of heap.Item.
        item, _ := minHeap.Pop()

        // This item has to fields Value (the node value) and Information (in the previous case, it will be the distance 30).
        // Refer to the heap.Item docs for more informations.
    }

For more information about the various methods please refere to the package documentation.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.