Skip to content

kerem37mert/linkedlist

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

LinkedList

install

  1. Download and install it:

    $ go get github.com/kerem37mert/linkedlist
  2. Import it in your code:

    import "github.com/kerem37mert/linkedlist"

Getting Started

Create a linked list

package main

import (
	"github.com/kerem37mert/linkedlist"
)

func main() {
	myList := linkedlist.New()
}

Adding element to linked list and traversal

package main

import (
	"github.com/kerem37mert/linkedlist"
)

func main() {
	myList := linkedlist.New()

	myList.Add("go")
	myList.Add("rust")
	myList.Add("c++")

	myList.Traversal()
}

Remove linked list element by value

package main

import (
	"github.com/kerem37mert/linkedlist"
)

func main() {
	myList := linkedlist.New()

	myList.Add("go")
	myList.Add("rust")
	myList.Add("c++")

	myList.Remove("go")
}

Remove linked list element by index

package main

import (
	"github.com/kerem37mert/linkedlist"
)

func main() {
	myList := linkedlist.New()

	myList.Add("go")
	myList.Add("rust")
	myList.Add("c++")

	myList.RemoveIndex(0)
}

Update value by index

package main

import (
	"github.com/kerem37mert/linkedlist"
	"fmt"
)

func main() {
	myList := linkedlist.New()

	myList.Add("go")
	myList.Add("rust")
	myList.Add("c++")

	err := myList.Update(1, "C")
	if err != nil {
		fmt.Println(err)
	}
}

Using ForEach loop

package main

import (
	"github.com/kerem37mert/linkedlist"
	"fmt"
)

func main() {
	myList := linkedlist.New()

	myList.Add("go")
	myList.Add("rust")
	myList.Add("c++")

	myList.ForEach(func(index uint, value any) {
		fmt.Println(value)
	})
}