lisp2arx
Visual Programming for AutoLisp Mathématiques en programmation Lisp.. doc2cpp,doc2lsp, sld2lsp, bmp2dcl, free__GifCcapture for all-CAD'platforms..
Lista Forumurilor Pe Tematici
lisp2arx | Reguli | Inregistrare | Login

POZE LISP2ARX

Nu sunteti logat.
Nou pe simpatie:
luana_21 pe Simpatie
Femeie
21 ani
Prahova
cauta Barbat
21 - 47 ani
lisp2arx / Delphi , InnoPascal / Delphi32 - How xchg on complex variabile?  
Autor
Mesaj Pagini: 1
admin
Administrator

Din: Bucharest
Inregistrat: acum 13 ani
Postari: 506
I need xchg for all-types-variabile., but the function xchg_han() have bugs
Xchg_han crash and he do not swap values.
Please help me...
Xchg(I,j) is alias Exchange(I, J);
How can I implement a quick sort in Delphi without getting Access violation
errors for large numbers of records?

Code:

type
      HMODULE= Cardinal;           { HMODULEs can be used in place of HINSTs }
      LHANDLE=HMODULE;
      PLHANDLE=^HMODULE;


type tap_idaloadintv6=record
           str:shortstring;  // index
           are:double;
           sub:byte;
           call:integer;
           retw:word;  //serial16
end;
Var HashTable:array[word] of tap_idaloadintv6;

Function xchg_han(a,b:pchar;extmin:word):boolean;
Var gap,nth:integer;swapOrder:dow;
Begin  result:=false;
       if (a=nil) or (b=nil) then exit else result:=true;
       if (extmin>3) then
          Begin gap:=extmin and 3;
                extmin:=extmin shr 2;
                 for nth:=1 to extmin do
                   Begin swapOrder:=PLHANDLE(a)^;
                         PLHANDLE(a)^:=PLHANDLE(b)^;
                         PLHANDLE(b)^:=swapOrder;
                         inc(a);inc(a);inc(a);inc(a);
                         inc(b);inc(b);inc(b);inc(b);
                   End
      End
                    else gap:=extmin;

      for nth:=0 to gap do Begin extmin:=ord(a^);
                                 a^:=b^;
                                 b^:=chr(extmin);
                                 inc(a);inc(b);
                        End;
End;


Function QSort_HashTable(LowJitters,HighJitters:Integer):TrueBool;
Var p1,p2:pchar;
  procedure QuickSort(iLo, iHi: Integer);
  var Lo, Hi, Mid: Integer;
  begin
    Lo := iLo;
    Hi := iHi;
    Mid := HashTable[(Lo + Hi) div 2].nn_call;
    repeat
      while HashTable[Lo].nn_call < Mid do Inc(Lo);
      while HashTable[Hi].nn_call > Mid do Dec(Hi);
      if (Lo <= Hi) 
         (xchg_han(@(HashTable[Hi],@HashTable[lo],sizeof(tap_idaloadintv6)) 
              then 
          Begin 
                Inc(Lo);
                Dec(Hi);
         end;
    until Lo > Hi;
    if Hi > iLo then   QuickSort(iLo, Hi);
    if Lo < iHi then   QuickSort(Lo, iHi);
  end;
begin
  if (LowJitters>HighJitters) then  xchg_int(LowJitters,HighJitters);
  QuickSort(LowJitters,HighJitters);
  result:=true;
end;

Initialization

Code:

Initialization
      fillchar(HashTable,sizeof(HashTable),0);



_______________________________________


pus acum 3 ani
   
Pagini: 1  

Mergi la