impemented stacks and queues

This commit is contained in:
milarin 2023-01-20 22:05:08 +01:00
parent 7dc44b9cd2
commit a83a8ca68e
6 changed files with 36 additions and 14 deletions

View File

@ -1,8 +1,13 @@
package ds
type ArrayQueue[T any] ListQueue[T]
type ArrayQueue[T any] struct {
*ListQueue[T]
}
var _ Queue[int] = &ArrayQueue[int]{}
func NewArrayQueue[T any]() *ArrayQueue[T] {
stack := NewListQueue[T](new(ArrayList[T]))
return (*ArrayQueue[T])(stack)
return &ArrayQueue[T]{
ListQueue: NewListQueue[T](NewArrayList[T](0)),
}
}

View File

@ -1,8 +1,13 @@
package ds
type LinkedListQueue[T any] ListQueue[T]
type LinkedListQueue[T any] struct {
*ListQueue[T]
}
var _ Queue[int] = &LinkedListQueue[int]{}
func NewLinkedListQueue[T any]() *LinkedListQueue[T] {
stack := NewListQueue[T](new(LinkedList[T]))
return (*LinkedListQueue[T])(stack)
return &LinkedListQueue[T]{
ListQueue: NewListQueue[T](NewLinkedList[T]()),
}
}

View File

@ -1,8 +1,13 @@
package ds
type ArrayStack[T any] ListStack[T]
type ArrayStack[T any] struct {
*ListStack[T]
}
var _ Stack[int] = &ArrayStack[int]{}
func NewArrayStack[T any]() *ArrayStack[T] {
stack := NewListStack[T](new(ArrayList[T]))
return (*ArrayStack[T])(stack)
return &ArrayStack[T]{
ListStack: NewListStack[T](NewArrayList[T](0)),
}
}

View File

@ -1,8 +1,13 @@
package ds
type LinkedListStack[T any] ListStack[T]
func NewLinkedListStack[T any]() *ArrayStack[T] {
stack := NewListStack[T](new(LinkedList[T]))
return (*ArrayStack[T])(stack)
type LinkedListStack[T any] struct {
*ListStack[T]
}
var _ Stack[int] = &LinkedListStack[int]{}
func NewLinkedListStack[T any]() *LinkedListStack[T] {
return &LinkedListStack[T]{
ListStack: NewListStack[T](NewLinkedList[T]()),
}
}

View File

@ -1 +1,2 @@
package ds
// TODO

View File

@ -1 +1,2 @@
package ds
// TODO