Update sorting.service.ts
This commit is contained in:
@@ -6,8 +6,6 @@ import {SortData, SortSnapshot} from '../sorting.models';
|
|||||||
})
|
})
|
||||||
export class SortingService {
|
export class SortingService {
|
||||||
|
|
||||||
constructor() { }
|
|
||||||
|
|
||||||
private createSnapshot(array: SortData[]): SortSnapshot {
|
private createSnapshot(array: SortData[]): SortSnapshot {
|
||||||
return {
|
return {
|
||||||
array: array.map(item => ({ ...item }))
|
array: array.map(item => ({ ...item }))
|
||||||
@@ -25,7 +23,7 @@ export class SortingService {
|
|||||||
for (let j = 0; j < n - i - 1; j++) {
|
for (let j = 0; j < n - i - 1; j++) {
|
||||||
arr[j].state = 'comparing';
|
arr[j].state = 'comparing';
|
||||||
arr[j + 1].state = 'comparing';
|
arr[j + 1].state = 'comparing';
|
||||||
snapshots.push(this.createSnapshot(arr)); // Snapshot Vergleich
|
snapshots.push(this.createSnapshot(arr));
|
||||||
|
|
||||||
if (arr[j].value > arr[j + 1].value) {
|
if (arr[j].value > arr[j + 1].value) {
|
||||||
const temp = arr[j].value;
|
const temp = arr[j].value;
|
||||||
@@ -76,7 +74,7 @@ export class SortingService {
|
|||||||
|
|
||||||
private partition(arr: SortData[], low: number, high: number, snapshots: SortSnapshot[]): number {
|
private partition(arr: SortData[], low: number, high: number, snapshots: SortSnapshot[]): number {
|
||||||
const pivot = arr[high];
|
const pivot = arr[high];
|
||||||
arr[high].state = 'comparing'; // Pivot visualisieren
|
arr[high].state = 'comparing';
|
||||||
snapshots.push(this.createSnapshot(arr));
|
snapshots.push(this.createSnapshot(arr));
|
||||||
|
|
||||||
let i = (low - 1);
|
let i = (low - 1);
|
||||||
@@ -149,7 +147,6 @@ export class SortingService {
|
|||||||
arr[largest].state = 'unsorted';
|
arr[largest].state = 'unsorted';
|
||||||
}
|
}
|
||||||
|
|
||||||
// Vergleich Rechts
|
|
||||||
if (r < n) {
|
if (r < n) {
|
||||||
arr[r].state = 'comparing';
|
arr[r].state = 'comparing';
|
||||||
arr[largest].state = 'comparing';
|
arr[largest].state = 'comparing';
|
||||||
|
|||||||
Reference in New Issue
Block a user