Merge pull request 'Mark sorted bounds and clamp array size' (#10) from bugfix/sorting_fix into main
All checks were successful
Build & Push Frontend A / docker (push) Successful in 45s

Reviewed-on: #10
This commit was merged in pull request #10.
This commit is contained in:
2026-02-04 16:01:44 +01:00
2 changed files with 8 additions and 3 deletions

View File

@@ -64,6 +64,9 @@ export class SortingService {
changed = this.switchValuesIfCorrect(arr, i, snapshots, changed); changed = this.switchValuesIfCorrect(arr, i, snapshots, changed);
} }
arr[end].state = 'sorted';
snapshots.push(this.createSnapshot(arr));
//DONE //DONE
if (!changed) { if (!changed) {
break; break;
@@ -71,12 +74,12 @@ export class SortingService {
changed = false; changed = false;
end -= 1; end -= 1;
for (let i = end; i >= start; i--) { for (let i = end-1; i >= start; i--) {
changed = this.switchValuesIfCorrect(arr, i, snapshots, changed); changed = this.switchValuesIfCorrect(arr, i, snapshots, changed);
} }
arr[start].state = 'sorted';
snapshots.push(this.createSnapshot(arr));
} while (changed); } while (changed);
return snapshots; return snapshots;
} }

View File

@@ -11,6 +11,7 @@ import {SortData, SortSnapshot} from './sorting.models';
import { FormsModule } from '@angular/forms'; import { FormsModule } from '@angular/forms';
import {MatInput} from '@angular/material/input'; import {MatInput} from '@angular/material/input';
import {UrlConstants} from '../../../constants/UrlConstants'; import {UrlConstants} from '../../../constants/UrlConstants';
import {MIN} from '@angular/forms/signals';
@Component({ @Component({
selector: 'app-sorting', selector: 'app-sorting',
standalone: true, standalone: true,
@@ -49,6 +50,7 @@ export class SortingComponent implements OnInit {
newArraySizeSet() newArraySizeSet()
{ {
this.arraySize = Math.min(Math.max(this.arraySize, this.MIN_ARRAY_SIZE), this.MAX_ARRAY_SIZE);
if (this.arraySize == this.sortArray.length) if (this.arraySize == this.sortArray.length)
{ {
return; return;