qsort
Want to sort 5,000 10-byte strings in about 1/10th of a second? This will do it (at least on my PII-233!). The insertion sort manages the same task in about 60 seconds (even when optimized it still took about 15 seconds on the same machine).
AI
ИИ-обзор: This codebase represents a historical implementation of the logic described in the metadata. Our preservation engine analyzes the structure to provide context for modern developers.
Исходный код
Public Function QSort(strList() As String, lLbound As Long, lUbound As Long) ':::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::' '::: :::' '::: Routine: QSort :::' '::: Author: Mike Shaffer (after Rod Stephens, et al.) :::' '::: Date: 21-May-98 :::' '::: Purpose: Very fast sort of a string array :::' '::: Passed: strList String array :::' '::: lLbound Lower bound to sort (usually 1) :::' '::: lUbound Upper bound to sort (usually ubound()) :::' '::: Returns: strList (in sorted order) :::' '::: Copyright: Copyright *c* 1998, Mike Shaffer :::' '::: ALL RIGHTS RESERVED WORLDWIDE :::' '::: Permission granted to use in any non-commercial :::' '::: product with credit where due. For free :::' '::: commercial license contact [email protected] :::' '::: Revisions: 22-May-98 Added and then dropped revision :::' '::: using CopyMemory rather than the simple swap :::' '::: when it was found to not provide much benefit. :::' '::: :::' ':::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::' Dim strTemp As String Dim strBuffer As String Dim lngCurLow As Long Dim lngCurHigh As Long Dim lngCurMidpoint As Long lngCurLow = lLbound ' Start current low and high at actual low/high lngCurHigh = lUbound If lUbound <= lLbound Then Exit Function ' Error! lngCurMidpoint = (lLbound + lUbound) \ 2 ' Find the approx midpoint of the array strTemp = strList(lngCurMidpoint) ' Pick as a starting point (we are making ' an assumption that the data *might* be ' in semi-sorted order already! Do While (lngCurLow <= lngCurHigh) Do While strList(lngCurLow) < strTemp lngCurLow = lngCurLow + 1 If lngCurLow = lUbound Then Exit Do Loop Do While strTemp < strList(lngCurHigh) lngCurHigh = lngCurHigh - 1 If lngCurHigh = lLbound Then Exit Do Loop If (lngCurLow <= lngCurHigh) Then ' if low is <= high then swap strBuffer = strList(lngCurLow) strList(lngCurLow) = strList(lngCurHigh) strList(lngCurHigh) = strBuffer ' lngCurLow = lngCurLow + 1 ' CurLow++ lngCurHigh = lngCurHigh - 1 ' CurLow-- End If Loop If lLbound < lngCurHigh Then ' Recurse if necessary QSort strList(), lLbound, lngCurHigh End If If lngCurLow < lUbound Then ' Recurse if necessary QSort strList(), lngCurLow, lUbound End If End Function Upload <html> <head> <title>Upload and log Files To Server</title> </head> <body> <!-- Retryx.com web design. All code copyright 2003 by retryx design. --> <!-- All right reserved. For more info please e-mail: [email protected] --> <!-- Requires PHP and MySQL on host server. --> <!-- PHP code to upload files to a directory on your host server and --> <!-- log the file name and title in a MySQL database. --> <!-- MySQL requires a table with the following fields: --> <!-- field: id type: INT not_null, auto_increment, primary --> <!-- field: title type: TEXT not_null --> <!-- field: filename type: TEXT not_null --> <!-- PHP code start --> <? //*********************************** //*********************************** //Upload directory path (absolute) $uploadpath = "/full/directory/path/to/upload/file"; //*********************************** //*********************************** //Define Functions function upload($filename, $filename_name, $uploadpath, $title){ //*********************************** //*********************************** //MySQL Information //Database name $dbname = "databaseName"; //MySQL Login information $dbhost = "localhost"; $dbusername = "username"; $dbpassword = "password"; //Database table name $dbtable = "tableName"; //*********************************** //*********************************** //** Edit nothing below this point (except form function, for it's style!) ** copy($filename,$uploadpath."/".$filename_name); $database = mysql_connect($dbhost, $dbusername, $dbpassword) or die ("ERROR Cant connect to MySQL"); mysql_select_db($dbname, $database) or die("ERROR Cant connect to database"); $query = "INSERT INTO " . $dbtable . " (id, title, filename) VALUES (NULL,'$title','$filename_name')"; mysql_query($query); mysql_close($database); echo "$title"; echo "<p>Has been Uploaded!</p>"; //Change "index.php" to whatever you call this page echo "<a href=\"index.php\">Upload another file?</a>"; } //******************************************************* //Form function, change the style of this if you need to! function form(){?> <form name= "form1"form method="post"action="<?=$_SERVER['PHP_SELF']?>"enctype="multipart/form-data"> <p> <input type="file" name="filename"></p><p> <input type="text" name="title"> <strong>Title</strong></p><p> <input name="Submit" type="submit" id="Submit" value="Upload"> <input type="hidden" name="formaction" value="uploadNow"> <input name="reset" type="reset" id="reset" value="Clear"> </p> </form><? } //******************************************************* //End Functions switch ($formaction){ default: form(); break; case "uploadNow": if ($filename=="none") { echo("*** No information given! ***");} else{ upload($filename, $filename_name, $uploadpath, $title); break;} break; } //End of upload script ?> <!-- PHP code End --> </body> </html> Upload
Оригинальные комментарии (3)
Восстановлено из Wayback Machine