Einzelnen Beitrag anzeigen

Benutzerbild von dummzeuch
dummzeuch

Registriert seit: 11. Aug 2012
Ort: Essen
1.679 Beiträge
 
Delphi 10.2 Tokyo Professional
 
#5

AW: LM Studio mit deepseek-r1-distill-qwen-7b

  Alt 2. Apr 2025, 18:03
Ich habe es jetzt hinbekommen, die "KI" in die IDE einzubinden. Jeder Aufruf dauert natürlich ewig, weil der PC dafür schlicht nicht geeignet ist. Aber es funktioniert.

Blöd ist, dass während sie auf die Antwort wartet, die IDE komplett blockiert ist. Ich will mir als Test gerade eine InsertionSort Implementation erklären lassen und hätte jetzt gerne den Sourcecode hier rein kopiert.

Edit: So, die Antwort ist da.

Code, der zu erklären war:

Delphi-Quellcode:
procedure SomeSort(Left, Right: Integer; CompareFunc: TCompareFunction; SwapProc: TSwapProcedure);
var
  I, J: Integer;
begin
  for I := Left + 1 to Right do begin
    J := I;
    while (J > Left) and (CompareFunc(J - 1, J) > 0) do begin
      SwapProc(J - 1, J);
      Dec(J);
    end;
  end;
end;
Erklärung

Zitat:
The code provided is
an implementation of the **bubble sort** algorithm tailored to use custom comparison and swap
functions. Here's a step-by-step explanation:

1. **Procedure Definition**: `SomeSort` takes four
parameters: two integers (`Left` and `Right`) defining the range of indices, a function pointer
`CompareFunc`, and a procedure pointer `SwapProc`.

2. **Loop Structure**:
- The outer loop
runs from `Left + 1` to `Right`, setting an index `I` for each iteration.
- For each `I`,
initialize another index `J` to `I`.

3. **Comparison and Swapping**:
- A while loop checks if
`J` is greater than `Left` and if `CompareFunc(J-1, J)` returns a positive value, indicating
elements at positions `J-1` and `J` are out of order.
- If conditions are met, swap the elements
using `SwapProc`, then decrement `J`.

4. **Termination**:
- The process continues until all
elements in the specified range are sorted according to the comparison logic defined by
`CompareFunc`.

This implementation is akin to a custom bubble sort that uses user-defined
functions for comparisons and swaps, ensuring flexibility in sorting criteria while maintaining an
in-place sorting mechanism.
Hm, Ich bin auch da nicht wirklich überzeugt.
Thomas Mueller

Geändert von dummzeuch ( 2. Apr 2025 um 18:14 Uhr)
  Mit Zitat antworten Zitat