Change queues and stacks

- Make chain element private
- Remove JSON Marshaller from stack and queue
- Remove access to top chain element
This commit is contained in:
Melody Becker 2025-04-24 15:52:43 +02:00
parent 9870d87d41
commit 09de0a19e1
Signed by: mstar
SSH key fingerprint: SHA256:9VAo09aaVNTWKzPW7Hq2LW+ox9OdwmTSHRoD4mlz1yI
3 changed files with 18 additions and 52 deletions

View file

@ -1,15 +1,15 @@
package containers
type ChainElem[T any] struct {
type chainElem[T any] struct {
Elem *T
Next *ChainElem[T]
Next *chainElem[T]
}
// reachable checks if you can reach elem l when starting from elem f.
// It detects loops and returns false if it runs into one.
func reachable[T any](f, l *ChainElem[T]) bool {
func reachable[T any](f, l *chainElem[T]) bool {
// Map to keep track of nodes already visited
checks := make(map[*ChainElem[T]]bool)
checks := make(map[*chainElem[T]]bool)
for w := f; w != l; w = w.Next {
if w == nil {
return false
@ -26,8 +26,8 @@ func reachable[T any](f, l *ChainElem[T]) bool {
}
// emptyElem creates a new ChainElem[T] with empty values.
func emptyElem[T any]() *ChainElem[T] {
return &ChainElem[T]{
func emptyElem[T any]() *chainElem[T] {
return &chainElem[T]{
Elem: nil,
Next: nil,
}