|
|
@ -33,7 +33,7 @@ Implementation of various data structures in Go.
|
|
|
|
All data structures implement the container interface with the following methods:
|
|
|
|
All data structures implement the container interface with the following methods:
|
|
|
|
|
|
|
|
|
|
|
|
```go
|
|
|
|
```go
|
|
|
|
type Interface interface {
|
|
|
|
type Container interface {
|
|
|
|
Empty() bool
|
|
|
|
Empty() bool
|
|
|
|
Size() int
|
|
|
|
Size() int
|
|
|
|
Clear()
|
|
|
|
Clear()
|
|
|
@ -47,7 +47,7 @@ Container specific operations:
|
|
|
|
// Returns sorted container's elements with respect to the passed comparator.
|
|
|
|
// Returns sorted container's elements with respect to the passed comparator.
|
|
|
|
// Does not effect the ordering of elements within the container.
|
|
|
|
// Does not effect the ordering of elements within the container.
|
|
|
|
// Uses timsort.
|
|
|
|
// Uses timsort.
|
|
|
|
func GetSortedValues(container Interface, comparator utils.Comparator) []interface{} {
|
|
|
|
func GetSortedValues(container Container, comparator utils.Comparator) []interface{} {
|
|
|
|
```
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
####Sets
|
|
|
|
####Sets
|
|
|
@ -57,12 +57,12 @@ A set is a data structure that can store elements and no repeated values. It is
|
|
|
|
All sets implement the set interface with the following methods:
|
|
|
|
All sets implement the set interface with the following methods:
|
|
|
|
|
|
|
|
|
|
|
|
```go
|
|
|
|
```go
|
|
|
|
type Interface interface {
|
|
|
|
type Set interface {
|
|
|
|
Add(elements ...interface{})
|
|
|
|
Add(elements ...interface{})
|
|
|
|
Remove(elements ...interface{})
|
|
|
|
Remove(elements ...interface{})
|
|
|
|
Contains(elements ...interface{}) bool
|
|
|
|
Contains(elements ...interface{}) bool
|
|
|
|
|
|
|
|
|
|
|
|
containers.Interface
|
|
|
|
containers.Container
|
|
|
|
// Empty() bool
|
|
|
|
// Empty() bool
|
|
|
|
// Size() int
|
|
|
|
// Size() int
|
|
|
|
// Clear()
|
|
|
|
// Clear()
|
|
|
@ -131,7 +131,7 @@ A list is a data structure that can store values and may have repeated values. T
|
|
|
|
All lists implement the list interface with the following methods:
|
|
|
|
All lists implement the list interface with the following methods:
|
|
|
|
|
|
|
|
|
|
|
|
```go
|
|
|
|
```go
|
|
|
|
type Interface interface {
|
|
|
|
type List interface {
|
|
|
|
Get(index int) (interface{}, bool)
|
|
|
|
Get(index int) (interface{}, bool)
|
|
|
|
Remove(index int)
|
|
|
|
Remove(index int)
|
|
|
|
Add(values ...interface{})
|
|
|
|
Add(values ...interface{})
|
|
|
@ -140,7 +140,7 @@ type Interface interface {
|
|
|
|
Swap(index1, index2 int)
|
|
|
|
Swap(index1, index2 int)
|
|
|
|
Insert(index int, values ...interface{})
|
|
|
|
Insert(index int, values ...interface{})
|
|
|
|
|
|
|
|
|
|
|
|
containers.Interface
|
|
|
|
containers.Container
|
|
|
|
// Empty() bool
|
|
|
|
// Empty() bool
|
|
|
|
// Size() int
|
|
|
|
// Size() int
|
|
|
|
// Clear()
|
|
|
|
// Clear()
|
|
|
@ -267,12 +267,12 @@ The stack interface represents a last-in-first-out (LIFO) collection of objects.
|
|
|
|
|
|
|
|
|
|
|
|
All stacks implement the stack interface with the following methods:
|
|
|
|
All stacks implement the stack interface with the following methods:
|
|
|
|
```go
|
|
|
|
```go
|
|
|
|
type Interface interface {
|
|
|
|
type Stack interface {
|
|
|
|
Push(value interface{})
|
|
|
|
Push(value interface{})
|
|
|
|
Pop() (value interface{}, ok bool)
|
|
|
|
Pop() (value interface{}, ok bool)
|
|
|
|
Peek() (value interface{}, ok bool)
|
|
|
|
Peek() (value interface{}, ok bool)
|
|
|
|
|
|
|
|
|
|
|
|
containers.Interface
|
|
|
|
containers.Container
|
|
|
|
// Empty() bool
|
|
|
|
// Empty() bool
|
|
|
|
// Size() int
|
|
|
|
// Size() int
|
|
|
|
// Clear()
|
|
|
|
// Clear()
|
|
|
@ -340,13 +340,13 @@ Structure that maps keys to values. A map cannot contain duplicate keys and each
|
|
|
|
|
|
|
|
|
|
|
|
All maps implement the map interface with the following methods:
|
|
|
|
All maps implement the map interface with the following methods:
|
|
|
|
```go
|
|
|
|
```go
|
|
|
|
type Interface interface {
|
|
|
|
type Map interface {
|
|
|
|
Put(key interface{}, value interface{})
|
|
|
|
Put(key interface{}, value interface{})
|
|
|
|
Get(key interface{}) (value interface{}, found bool)
|
|
|
|
Get(key interface{}) (value interface{}, found bool)
|
|
|
|
Remove(key interface{})
|
|
|
|
Remove(key interface{})
|
|
|
|
Keys() []interface{}
|
|
|
|
Keys() []interface{}
|
|
|
|
|
|
|
|
|
|
|
|
containers.Interface
|
|
|
|
containers.Container
|
|
|
|
// Empty() bool
|
|
|
|
// Empty() bool
|
|
|
|
// Size() int
|
|
|
|
// Size() int
|
|
|
|
// Clear()
|
|
|
|
// Clear()
|
|
|
@ -420,8 +420,8 @@ A tree is a widely used data data structure that simulates a hierarchical tree s
|
|
|
|
|
|
|
|
|
|
|
|
All trees implement the tree interface with the following methods:
|
|
|
|
All trees implement the tree interface with the following methods:
|
|
|
|
```go
|
|
|
|
```go
|
|
|
|
type Interface interface {
|
|
|
|
type Tree interface {
|
|
|
|
containers.Interface
|
|
|
|
containers.Container
|
|
|
|
// Empty() bool
|
|
|
|
// Empty() bool
|
|
|
|
// Size() int
|
|
|
|
// Size() int
|
|
|
|
// Clear()
|
|
|
|
// Clear()
|
|
|
|