BBS: Inland Empire Archive Date: 03-28-93 (21:04) Number: 246 From: QUINN TYLER JACKSON Refer#: NONE To: ALL Recvd: NO Subj: Quik_Bas Faq2.1 3/ Conf: (2) Quik_Bas

>>> Continued from previous message But, if you want ALL the variables to be STATIC, use the following method:SUBFooSub ()STATIC: : :ENDSUBThere are certain speed advantages toSTATICSUBs and FUNCTIONs, since variables are not created on the stack, but that is a more advanced issue. So, in summary: 1.SHAREDallows SUBs and FUNCTIONs to use modular variables, 2.COMMONallows modules to share variables between themselves, 3.STATICallows variables to retain their value between calls to theSUBorFUNCTIONin question. Q2.0 Commonly Requested Routines: Q2.4 Okay, I've looked the whole thing over, Quinn, and I've realized something: the recursive QuickSortXXX routine eats the stack up pretty fast. Is there another way? Is there a way to implement a QuickSortSUBwithout using recursion? A2.4 Yes, indeed there is. Cornel Huth implemented an iterative quicksort algorithm, which I then tweaked a bit. It is actually a bit faster than the other, and doesn't use too much of the stack. It accomplishes this by using an array to simulate a stack. The modified version follows: S2.0 HUTHSORT.BAS [P210S02.BAS]' HUTHSORT.BAS written by Cornel Huth' Iterative QuickSort Routine'' Tweaked by Quinn Tyler JacksonSUBsubHuthSortSTR (Array()ASSTRING)' ^ TWEAK THESE ^' |FOROTHER TYPES |' `--+--------------'' VDIMcompareASSTRINGTYPEStackType lowASINTEGERhiASINTEGERENDTYPEDIMaStack(1TO128)ASStackType StackPtr = 1 aStack(StackPtr).low = LBOUND(Array) aStack(StackPtr).hi = UBOUND(Array) StackPtr = StackPtr + 1DOStackPtr = StackPtr - 1 low = aStack(StackPtr).low hi = aStack(StackPtr).hiDOi = low j = hi mid = (low + hi) \ 2 compare = Array(mid)DODOWHILEArray(i) < compare i = i + 1LOOPDOWHILEArray(j) > compare j = j - 1LOOPIFi <= jTHENSWAPArray(i), Array(j) i = i + 1 j = j - 1ENDIFLOOPWHILEi <= jIFj - low < hi - iTHENIFi < hiTHENaStack(StackPtr).low = i aStack(StackPtr).hi = hi StackPtr = StackPtr + 1ENDIFhi = jELSEIFlow < jTHENaStack(StackPtr).low = low aStack(StackPtr).hi = j StackPtr = StackPtr + 1ENDIFlow = iENDIFLOOPWHILElow < hi'IF StackPtr > maxspTHENmaxsp = StackPtrLOOPWHILEStackPtr <> 1ENDSUB=======>8 SAMPLE 2.0 ENDS HERE 8<========= Q2.5 Now that I've got so many neat ways to sort a list, I'd sure like to be able to locate an entry in it quickly. I hear that a binary search is fast, but I just can't figure out how to do that. How do I do a binary search? A2.5 Binary searches are the fastest overall search method for standard sorted lists. Such lists can be divided in two, looked at, and divided again as necessary. A good search method is demonstrated here: S3.0 BISEARCH.BAS [F210S03.BAS]DEFINTA-ZFUNCTIONBiSearchSTR (FindASSTRING, Array() AS STRING) Min = LBOUND(Array)'start at first elementMax = UBOUND(Array)'consider through lastDOTry = (Max + Min) \ 2'start testing in middleIFArray(Try) = FindTHEN'found it!BiSearch = Try'return matching elementEXITDO'all doneENDIFIFArray(Try) > FindTHEN'too high, cut in halfMax = Try - 1ELSEMin = Try + 1'too low, cut other wayENDIFLOOPWHILEMax >= MinENDFUNCTION=======>8 SAMPLE 3.0 ENDS HERE 8<========= Q3.0 Advanced Topics -- "Hashing in QuickBASIC" >>> Continued to next message * OLX 2.1 TD * Post all questions in this box --> [] --- Maximus 2.01wb * Origin: VKUG/VPCC QuickBasic Echo - Richmond, BC (1:153/151)

Echo Basic Postings

**Books at Amazon:**

Back to BASIC: The History, Corruption, and Future of the Language

Hackers: Heroes of the Computer Revolution (including Tiny BASIC)

Go to: The Story of the Math Majors, Bridge Players, Engineers, Chess Wizards, Scientists and Iconoclasts who were the Hero Programmers of the Software Revolution

The Advent of the Algorithm: The Idea that Rules the World

Moths in the Machine: The Power and Perils of Programming

Mastering Visual Basic .NET