linkedlist

package module
v0.0.0-...-9cc133a Latest Latest
Warning

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

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

README

Single Linked List

Single Linkedlist Definition

A linked list is a linear collection of data elements whose order is not given by their physical placement in memory. Instead, each element points to the next. It is a data structure consisting of a collection of nodes which together represent a sequence. In its most basic form, each node contains: data, and a reference (in other words, a link) to the next node in the sequence. This structure allows for efficient insertion or removal of elements from any position in the sequence during iteration.

linked list

The principal benefit of a linked list over a conventional array is that the list elements can be easily inserted or removed without reallocation or reorganization of the entire structure because the data items need not be stored contiguously in memory or on disk, while restructuring an array at run-time is a much more expensive operation. Linked lists allow insertion and removal of nodes at any point in the list, and allow doing so with a constant number of operations by keeping the link previous to the link being added or removed in memory during list traversal.

This module serves as the base for all executable. So we don't have to redefine the Node, Linkedlist and the basic methods while solving the problems.

Documentation

Overview

Package linkedlist implements:

Create a a new Linkedlist and Node
Insert a Node at the beginning of the list
Insert a Node at the end of the list
Delete a Node from the beginning of the list
Delete a Node from the end of the list
Print the Linkedlis

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Linkedlist

type Linkedlist struct {
	Length int
	Head   *Node
}

Linkedlist struct holds a linked list

func NewLinkedlist

func NewLinkedlist() *Linkedlist

NewLinkedlist creates a new linked list

func (*Linkedlist) AddAtBeg

func (ll *Linkedlist) AddAtBeg(val int)

AddAtBeg adds a Node at the beginning of the list

func (*Linkedlist) AddAtEnd

func (ll *Linkedlist) AddAtEnd(val int)

AddAtEnd adds a Node at the end of the list

func (*Linkedlist) DelAtBeg

func (ll *Linkedlist) DelAtBeg() int

DelAtBeg deletes a node from the beginning of the list

func (*Linkedlist) DelAtEnd

func (ll *Linkedlist) DelAtEnd() int

DelAtEnd deletes a node from the end of the list

func (*Linkedlist) DeleteWithValute

func (ll *Linkedlist) DeleteWithValute(val int) int

DeleteWithValute deletes a node which value is equal to the function parameter

func (*Linkedlist) String

func (ll *Linkedlist) String() string

utility function to print the linkedlist

type Node

type Node struct {
	Val  int
	Next *Node
}

Node struct holds a node

func NewNode

func NewNode(val int) *Node

NewNode creates a new node

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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