singly-linked-list

command
v0.0.0-...-a2a1f02 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2020 License: MIT Imports: 1 Imported by: 0

README

singly-linked-list example

A singly linked list (i.e. using just a head pointer).

GitHub Webpage

SINGLY LINKED LIST

Linked Lists function as an array that can grow and shrink as needed, from any point in the list.

Each Node contains data Value and a pointer NEXT to the next Node in the list. If the pointer is null, you are at the end of the list.

head -> VALUE|NEXT -> VALUE|NEXT -> VALUE|(null)

A local head pointer variable points to the first item of a list.

A example of a Node is created by a struct,

type Node struct {
    Value
    next  *Node
}

Where Value can be something like,

type Value struct {
    name   string
    age    int
    gender string
}

This illustration may help,

IMAGE - singly-linked-list - IMAGE

Advantages over arrays
  • Nodes can be added or removed from middle of list
  • There is no need to define size
Disadvantages over arrays
  • You must iterate over the list until you get to the node you want
  • Dynamic pointers required
  • larger overhead

RUN

go run linked-list.go

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

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