Mark sorted bounds and clamp array size #10

Merged
lobo merged 1 commits from bugfix/sorting_fix into main 2026-02-04 16:01:45 +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);
}
arr[end].state = 'sorted';
snapshots.push(this.createSnapshot(arr));
//DONE
if (!changed) {
break;
@@ -71,12 +74,12 @@ export class SortingService {
changed = false;
end -= 1;
for (let i = end; i >= start; i--) {
for (let i = end-1; i >= start; i--) {
changed = this.switchValuesIfCorrect(arr, i, snapshots, changed);
}
arr[start].state = 'sorted';
snapshots.push(this.createSnapshot(arr));
} while (changed);
return snapshots;
}

View File

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