Data update
This commit is contained in:
parent
5150844a7d
commit
4bb20c9b71
7735 changed files with 38060 additions and 199180 deletions
|
|
@ -1,9 +0,0 @@
|
|||
-----------------------------------------------------------------------
|
||||
-- Generic Quick_Sort procedure
|
||||
-----------------------------------------------------------------------
|
||||
generic
|
||||
type Element is private;
|
||||
type Index is (<>);
|
||||
type Element_Array is array(Index range <>) of Element;
|
||||
with function "<" (Left, Right : Element) return Boolean is <>;
|
||||
procedure Quick_Sort(A : in out Element_Array);
|
||||
|
|
@ -1,44 +0,0 @@
|
|||
-----------------------------------------------------------------------
|
||||
-- Generic Quick_Sort procedure
|
||||
-----------------------------------------------------------------------
|
||||
|
||||
procedure Quick_Sort (A : in out Element_Array) is
|
||||
|
||||
procedure Swap(Left, Right : Index) is
|
||||
Temp : Element := A (Left);
|
||||
begin
|
||||
A (Left) := A (Right);
|
||||
A (Right) := Temp;
|
||||
end Swap;
|
||||
|
||||
begin
|
||||
if A'Length > 1 then
|
||||
declare
|
||||
Pivot_Value : Element := A (A'First);
|
||||
Right : Index := A'Last;
|
||||
Left : Index := A'First;
|
||||
begin
|
||||
loop
|
||||
while Left < Right and not (Pivot_Value < A (Left)) loop
|
||||
Left := Index'Succ (Left);
|
||||
end loop;
|
||||
while Pivot_Value < A (Right) loop
|
||||
Right := Index'Pred (Right);
|
||||
end loop;
|
||||
exit when Right <= Left;
|
||||
Swap (Left, Right);
|
||||
Left := Index'Succ (Left);
|
||||
Right := Index'Pred (Right);
|
||||
end loop;
|
||||
if Right = A'Last then
|
||||
Right := Index'Pred (Right);
|
||||
Swap (A'First, A'Last);
|
||||
end if;
|
||||
if Left = A'First then
|
||||
Left := Index'Succ (Left);
|
||||
end if;
|
||||
Quick_Sort (A (A'First .. Right));
|
||||
Quick_Sort (A (Left .. A'Last));
|
||||
end;
|
||||
end if;
|
||||
end Quick_Sort;
|
||||
|
|
@ -1,32 +0,0 @@
|
|||
with Ada.Text_Io;
|
||||
with Ada.Float_Text_IO; use Ada.Float_Text_IO;
|
||||
with Quick_Sort;
|
||||
|
||||
procedure Sort_Test is
|
||||
type Days is (Mon, Tue, Wed, Thu, Fri, Sat, Sun);
|
||||
type Sales is array (Days range <>) of Float;
|
||||
procedure Sort_Days is new Quick_Sort(Float, Days, Sales);
|
||||
|
||||
procedure Print (Item : Sales) is
|
||||
begin
|
||||
for I in Item'range loop
|
||||
Put(Item => Item(I), Fore => 5, Aft => 2, Exp => 0);
|
||||
end loop;
|
||||
end Print;
|
||||
|
||||
Weekly_Sales : Sales := (Mon => 300.0,
|
||||
Tue => 700.0,
|
||||
Wed => 800.0,
|
||||
Thu => 500.0,
|
||||
Fri => 200.0,
|
||||
Sat => 100.0,
|
||||
Sun => 900.0);
|
||||
|
||||
begin
|
||||
|
||||
Print(Weekly_Sales);
|
||||
Ada.Text_Io.New_Line(2);
|
||||
Sort_Days(Weekly_Sales);
|
||||
Print(Weekly_Sales);
|
||||
|
||||
end Sort_Test;
|
||||
|
|
@ -1,66 +0,0 @@
|
|||
IDENTIFICATION DIVISION.
|
||||
PROGRAM-ID. quicksort RECURSIVE.
|
||||
|
||||
DATA DIVISION.
|
||||
LOCAL-STORAGE SECTION.
|
||||
01 temp PIC S9(8).
|
||||
|
||||
01 pivot PIC S9(8).
|
||||
|
||||
01 left-most-idx PIC 9(5).
|
||||
01 right-most-idx PIC 9(5).
|
||||
|
||||
01 left-idx PIC 9(5).
|
||||
01 right-idx PIC 9(5).
|
||||
|
||||
LINKAGE SECTION.
|
||||
78 Arr-Length VALUE 50.
|
||||
|
||||
01 arr-area.
|
||||
03 arr PIC S9(8) OCCURS Arr-Length TIMES.
|
||||
|
||||
01 left-val PIC 9(5).
|
||||
01 right-val PIC 9(5).
|
||||
|
||||
PROCEDURE DIVISION USING REFERENCE arr-area, OPTIONAL left-val,
|
||||
OPTIONAL right-val.
|
||||
IF left-val IS OMITTED OR right-val IS OMITTED
|
||||
MOVE 1 TO left-most-idx, left-idx
|
||||
MOVE Arr-Length TO right-most-idx, right-idx
|
||||
ELSE
|
||||
MOVE left-val TO left-most-idx, left-idx
|
||||
MOVE right-val TO right-most-idx, right-idx
|
||||
END-IF
|
||||
|
||||
IF right-most-idx - left-most-idx < 1
|
||||
GOBACK
|
||||
END-IF
|
||||
|
||||
COMPUTE pivot = arr ((left-most-idx + right-most-idx) / 2)
|
||||
|
||||
PERFORM UNTIL left-idx > right-idx
|
||||
PERFORM VARYING left-idx FROM left-idx BY 1
|
||||
UNTIL arr (left-idx) >= pivot
|
||||
END-PERFORM
|
||||
|
||||
PERFORM VARYING right-idx FROM right-idx BY -1
|
||||
UNTIL arr (right-idx) <= pivot
|
||||
END-PERFORM
|
||||
|
||||
IF left-idx <= right-idx
|
||||
MOVE arr (left-idx) TO temp
|
||||
MOVE arr (right-idx) TO arr (left-idx)
|
||||
MOVE temp TO arr (right-idx)
|
||||
|
||||
ADD 1 TO left-idx
|
||||
SUBTRACT 1 FROM right-idx
|
||||
END-IF
|
||||
END-PERFORM
|
||||
|
||||
CALL "quicksort" USING REFERENCE arr-area,
|
||||
CONTENT left-most-idx, right-idx
|
||||
CALL "quicksort" USING REFERENCE arr-area, CONTENT left-idx,
|
||||
right-most-idx
|
||||
|
||||
GOBACK
|
||||
.
|
||||
|
|
@ -40,10 +40,10 @@ extension op
|
|||
}
|
||||
}
|
||||
|
||||
public program()
|
||||
public Program()
|
||||
{
|
||||
var list := new int[]{3, 14, 1, 5, 9, 2, 6, 3};
|
||||
|
||||
console.printLine("before:", list.asEnumerable());
|
||||
console.printLine("after :", list.quickSort().asEnumerable());
|
||||
Console.printLine("before:", list.asEnumerable());
|
||||
Console.printLine("after :", list.quickSort().asEnumerable());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,10 +0,0 @@
|
|||
(require 'seq)
|
||||
|
||||
(defun quicksort (xs)
|
||||
(if (null xs)
|
||||
()
|
||||
(let* ((head (car xs))
|
||||
(tail (cdr xs))
|
||||
(lower-part (quicksort (seq-filter (lambda (x) (<= x head)) tail)))
|
||||
(higher-part (quicksort (seq-filter (lambda (x) (> x head)) tail))))
|
||||
(append lower-part (list head) higher-part))))
|
||||
|
|
@ -1,52 +0,0 @@
|
|||
Function SortThree( [Array] $data )
|
||||
{
|
||||
if( $data[ 0 ] -gt $data[ 1 ] )
|
||||
{
|
||||
if( $data[ 0 ] -lt $data[ 2 ] )
|
||||
{
|
||||
$data = $data[ 1, 0, 2 ]
|
||||
} elseif ( $data[ 1 ] -lt $data[ 2 ] ){
|
||||
$data = $data[ 1, 2, 0 ]
|
||||
} else {
|
||||
$data = $data[ 2, 1, 0 ]
|
||||
}
|
||||
} else {
|
||||
if( $data[ 0 ] -gt $data[ 2 ] )
|
||||
{
|
||||
$data = $data[ 2, 0, 1 ]
|
||||
} elseif( $data[ 1 ] -gt $data[ 2 ] ) {
|
||||
$data = $data[ 0, 2, 1 ]
|
||||
}
|
||||
}
|
||||
$data
|
||||
}
|
||||
|
||||
Function QuickSort( [Array] $data, $rand = ( New-Object Random ) )
|
||||
{
|
||||
$datal = $data.length
|
||||
if( $datal -gt 3 )
|
||||
{
|
||||
[void] $datal--
|
||||
$median = ( SortThree $data[ 0, ( $rand.Next( 1, $datal - 1 ) ), -1 ] )[ 1 ]
|
||||
$lt = @()
|
||||
$eq = @()
|
||||
$gt = @()
|
||||
$data | ForEach-Object { if( $_ -lt $median ) { $lt += $_ } elseif( $_ -eq $median ) { $eq += $_ } else { $gt += $_ } }
|
||||
$lt = ( QuickSort $lt $rand )
|
||||
$gt = ( QuickSort $gt $rand )
|
||||
$data = @($lt) + $eq + $gt
|
||||
} elseif( $datal -eq 3 ) {
|
||||
$data = SortThree( $data )
|
||||
} elseif( $datal -eq 2 ) {
|
||||
if( $data[ 0 ] -gt $data[ 1 ] )
|
||||
{
|
||||
$data = $data[ 1, 0 ]
|
||||
}
|
||||
}
|
||||
$data
|
||||
}
|
||||
|
||||
QuickSort 5,3,1,2,4
|
||||
QuickSort 'e','c','a','b','d'
|
||||
QuickSort 0.5,0.3,0.1,0.2,0.4
|
||||
$l = 100; QuickSort ( 1..$l | ForEach-Object { $Rand = New-Object Random }{ $Rand.Next( 0, $l - 1 ) } )
|
||||
|
|
@ -1,15 +0,0 @@
|
|||
function quicksort($array) {
|
||||
$less, $equal, $greater = @(), @(), @()
|
||||
if( $array.Count -gt 1 ) {
|
||||
$pivot = $array[0]
|
||||
foreach( $x in $array) {
|
||||
if($x -lt $pivot) { $less += @($x) }
|
||||
elseif ($x -eq $pivot) { $equal += @($x)}
|
||||
else { $greater += @($x) }
|
||||
}
|
||||
$array = (@(quicksort $less) + @($equal) + @(quicksort $greater))
|
||||
}
|
||||
$array
|
||||
}
|
||||
$array = @(60, 21, 19, 36, 63, 8, 100, 80, 3, 87, 11)
|
||||
"$(quicksort $array)"
|
||||
|
|
@ -1,15 +0,0 @@
|
|||
function quicksort($in) {
|
||||
$n = $in.count
|
||||
switch ($n) {
|
||||
0 {}
|
||||
1 { $in[0] }
|
||||
2 { if ($in[0] -lt $in[1]) {$in[0], $in[1]} else {$in[1], $in[0]} }
|
||||
default {
|
||||
$pivot = $in | get-random
|
||||
$lt = $in | ? {$_ -lt $pivot}
|
||||
$eq = $in | ? {$_ -eq $pivot}
|
||||
$gt = $in | ? {$_ -gt $pivot}
|
||||
@(quicksort $lt) + @($eq) + @(quicksort $gt)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,6 +1,7 @@
|
|||
include Settings
|
||||
-- 24 Aug 2025
|
||||
include Setting
|
||||
|
||||
say 'QUICKSORT - 4 Mar 2025'
|
||||
say 'QUICKSORT'
|
||||
say version
|
||||
say
|
||||
numeric digits 9
|
||||
|
|
|
|||
|
|
@ -1,35 +0,0 @@
|
|||
Function quicksort(arr,s,n)
|
||||
If n < 2 Then
|
||||
Exit Function
|
||||
End If
|
||||
t = s + n - 1
|
||||
l = s
|
||||
r = t
|
||||
p = arr(Int((l + r)/2))
|
||||
Do Until l > r
|
||||
Do While arr(l) < p
|
||||
l = l + 1
|
||||
Loop
|
||||
Do While arr(r) > p
|
||||
r = r -1
|
||||
Loop
|
||||
If l <= r Then
|
||||
tmp = arr(l)
|
||||
arr(l) = arr(r)
|
||||
arr(r) = tmp
|
||||
l = l + 1
|
||||
r = r - 1
|
||||
End If
|
||||
Loop
|
||||
If s < r Then
|
||||
Call quicksort(arr,s,r-s+1)
|
||||
End If
|
||||
If l < t Then
|
||||
Call quicksort(arr,l,t-l+1)
|
||||
End If
|
||||
quicksort = arr
|
||||
End Function
|
||||
|
||||
myarray=Array(9,8,7,6,5,5,4,3,2,1,0,-1)
|
||||
m = quicksort(myarray,0,12)
|
||||
WScript.Echo Join(m,",")
|
||||
Loading…
Add table
Add a link
Reference in a new issue