Skip to content

Commit f106116

Browse files
committed
minor fixes
1 parent 8252c9b commit f106116

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

src/Algorithm/Various/Permutation.php

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,16 +66,33 @@ public function stringPermutations(string $string): array {
6666
*/
6767
private function permute(array $objects, $prefix, array $result) {
6868
$length = \count($objects);
69+
//if there are no elements in the array,
70+
//a permutation is found. The permutation is
71+
//added to the array
6972
if (0 === $length) {
7073
$result[] = $prefix;
71-
} else {
74+
}
75+
//if the number of elements in the array
76+
//is greater than 0, there are more elements
77+
//to build an permutation.
78+
else {
79+
//The length is decreased by each recursive function call
7280
for ($i = 0; $i < $length; $i++) {
81+
//a new prefix is created. The prefix consists of the
82+
//actual prefix ("" at the beginning) and the next element
83+
//in the objects array
84+
$newPrefix = $prefix . $objects[$i];
85+
86+
//since the ith element in objects is used as a prefix,
87+
//the remaining objects have to be sliced by exactly this
88+
//object in order to prevent a reoccurrence of the element in
89+
//the permutation
7390
$newObjects = \array_merge(
7491
\array_slice($objects, 0, $i),
7592
\array_slice($objects, $i + 1)
7693
);
77-
$newPrefix = $prefix . $objects[$i];
7894

95+
//call the permute method with the new prefix and objects
7996
$result = $this->permute($newObjects, $newPrefix, $result);
8097
}
8198
}

src/Datastructure/Stackqueue/FixedStack.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,6 @@ public function __construct(int $maxSize) {
5252
protected function isValid(): bool {
5353
$parent = parent::isValid();
5454
$maxSize = parent::stackSize() < $this->maxSize;
55-
//echo parent::stackSize();
56-
//echo "\n";
57-
//echo $this->maxSize;
58-
//echo "\n";
5955
return $parent && $maxSize;
6056
}
6157

0 commit comments

Comments
 (0)