darray

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Dec 11, 2023 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package darray provides an implementation of a dynamic array data structure.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DynamicArray

type DynamicArray[T comparable] struct {
	// contains filtered or unexported fields
}

DynamicArray is a struct that represents a dynamic array.

func NewDynamicArray

func NewDynamicArray[T comparable](args ...int) *DynamicArray[T]

NewDynamicArray creates a new dynamic array with the given capacity. If no capacity is given, it defaults to 16.

func (*DynamicArray[T]) Add

func (d *DynamicArray[T]) Add(elem int)

Add adds the given element to the dynamic array.

func (*DynamicArray[T]) Contains

func (d *DynamicArray[T]) Contains(elem int) bool

Contains returns true if the dynamic array contains the given element.

func (*DynamicArray[T]) Get

func (d *DynamicArray[T]) Get(index int) int

Get returns the element at the given index.

func (*DynamicArray[T]) IsEmpty

func (d *DynamicArray[T]) IsEmpty() bool

IsEmpty returns true if the dynamic array is empty.

func (*DynamicArray[T]) Qsort

func (d *DynamicArray[T]) Qsort()

Qsort sorts the dynamic array using the quicksort algorithm.

func (*DynamicArray[T]) Remove

func (d *DynamicArray[T]) Remove(elem int) error

Remove removes the given element from the dynamic array.

func (*DynamicArray[T]) RemoveAt

func (d *DynamicArray[T]) RemoveAt(index int)

RemoveAt removes the element at the given index from the dynamic array.

func (*DynamicArray[T]) Reverse

func (d *DynamicArray[T]) Reverse()

Reverse reverses the order of the elements in the dynamic array.

func (*DynamicArray[T]) Set

func (d *DynamicArray[T]) Set(index int, elem int)

Set sets the element at the given index to the given value.

func (*DynamicArray[T]) Size

func (d *DynamicArray[T]) Size() int

Size returns the number of elements in the dynamic array.

func (*DynamicArray[T]) ToString

func (d *DynamicArray[T]) ToString() string

ToString returns a string representation of the dynamic array.

Jump to

Keyboard shortcuts

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