adt

package
v0.0.0-...-820286c Latest Latest
Warning

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

Go to latest
Published: Dec 31, 2023 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Node

type Node[T any] struct {
	// contains filtered or unexported fields
}

Node represents a single node in linked list representation.

func NewNode

func NewNode[T any](data T) *Node[T]

NewNode creates an instance of Node with the data provided.

func (*Node[T]) Data

func (n *Node[T]) Data() T

Data returns the data from the Node.

func (*Node[T]) Display

func (n *Node[T]) Display()

Display displays the node to the console.

type Queue

type Queue[T any] struct {
	// contains filtered or unexported fields
}

Queue like Stack, is also an abstract data structure. The thing that makes queue different from stack is that a queue is open at both its ends. Hence, it follows FIFO (First-In-First-Out) structure, i.e. the data item inserted first will also be accessed first. The data is inserted into the queue through one end and deleted from it using the other end.

func NewQueue

func NewQueue[T any]() *Queue[T]

NewQueue creates an empty queue.

func (*Queue[T]) DeQueue

func (q *Queue[T]) DeQueue() (T, error)

DeQueue is a data manipulation operation that removes an element from the queue and returns it. If the queue is empty, it sets error.

func (*Queue[T]) Display

func (q *Queue[T]) Display()

Display prints the queue to the console

func (*Queue[T]) EnQueue

func (q *Queue[T]) EnQueue(data T)

EnQueue is a data manipulation operation that inserts an element into the queue.

func (*Queue[T]) Front

func (q *Queue[T]) Front() T

Front returns the front node in the queue, w/o deleting it. If Queue is empty, then it will return nil.

func (*Queue[T]) IsEmpty

func (q *Queue[T]) IsEmpty() bool

IsEmpty checks if queue is empty or not.

func (*Queue[T]) Rear

func (q *Queue[T]) Rear() T

Rear returns the rear node in the queue, w/o deleting it. If Queue is empty, then it will return nil.

func (*Queue[T]) Size

func (q *Queue[T]) Size() uint

Size returns the size of the queue.

type Stack

type Stack[T any] struct {
	// contains filtered or unexported fields
}

Stack represents the abstract data structure stack. It uses linked list representation to maintain the stack.

func NewStack

func NewStack[T any]() *Stack[T]

NewStack creates an empty stack.

func (*Stack[T]) Display

func (s *Stack[T]) Display()

Display prints the stack to the console.

func (*Stack[T]) IsEmpty

func (s *Stack[T]) IsEmpty() bool

IsEmpty checks if the stack is empty or not. This is called when performing any of Push, Pop and Display operations.

func (*Stack[T]) Pop

func (s *Stack[T]) Pop() (T, error)

Pop removes the top node from the stack and returns it.

func (*Stack[T]) Push

func (s *Stack[T]) Push(data T)

Push pushes new element to top of the stack.

func (*Stack[T]) Size

func (s *Stack[T]) Size() uint

Size returns the size of the stack.

func (*Stack[T]) Top

func (s *Stack[T]) Top() T

Top returns the top element from the stack, w/o deleting it.

type TraversalType

type TraversalType int
const (
	PreOrder TraversalType = iota
	InOrder
	PostOrder
)

type Tree

type Tree[T cmp.Ordered] struct {
	// contains filtered or unexported fields
}

func NewBinaryTree

func NewBinaryTree[T cmp.Ordered]() *Tree[T]

NewBinaryTree creates an empty tree.

func (*Tree[T]) Insert

func (t *Tree[T]) Insert(data T)

Insert inserts data into the tree.

func (*Tree[T]) IsEmpty

func (t *Tree[T]) IsEmpty() bool

func (*Tree[T]) Traverse

func (t *Tree[T]) Traverse(tType TraversalType)

Traverse prints the tree data based on TraversalType.

type TreeNode

type TreeNode[T cmp.Ordered] struct {
	// contains filtered or unexported fields
}

TreeNode represents a node in a tree data structure.

func NewTreeNode

func NewTreeNode[T cmp.Ordered](data T) *TreeNode[T]

Jump to

Keyboard shortcuts

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