private function arrayListToStringBuilder(ArrayList $arrayList, bool $reverse = false) {
        $stringBuilder = new StringBuilder();
        if ($reverse) {
            $stack = new Stack();
            foreach ($arrayList as $item) {
                if (null !== $item) {
                    $stack->push($item);
                }
            }
            while (!$stack->isEmpty()) {
                $stringBuilder->append($stack->pop());
            }
        } else {
            $queue = new Queue();
            foreach ($arrayList as $item) {
                if (null !== $item) {
                    $queue->enqueue($item);
                }

            }
            while (!$queue->isEmpty()) {
                $stringBuilder->append($queue->dequeue());
            }
        }
        return $stringBuilder;
    }