===MMBasic - Create/Manipulate Stack, Queue or List=== {{ :migratedattachments:mmbasic_original:stack_queue_list_utilities.zip?linkonly}} Stack, Queue and List Routines for Strings and Numeric values ==================================================================================== Code is included in the zipped attachment String Operations ----------------- S.STACK.CREATE string$,width Create a string as a holder for multiple substrings of width characters long for use as a Last In, First Out (LIFO) stack. Maximum number of substrings is width x number of substrings =< 250. Eg. max 25 of 10 character longs strings. Strings of less than width are right justified and padded with spaces. Routine returns with string$ set up as the holder with the width in character positions 1 and 2 (maximum 99) and a pointer to the bottom of the stack + 1 in positions 3, 4 and 5. S.STACK.PUSH string$,data$ Push data$ onto stack string$. If data$ is shorter than width, data$ is right justified and padded with spaces. S.STACK.POP$(string$) Function to pop the top substring off the stack string$. All string stack operations are checked for overflow, underflow or substrings too wide. Queue Operations ---------------- S.QUEUE.CREATE string$,width Create a string as a holder for multiple substrings of width characters long for use as a First In, First Out (FIFO) queue. Maximum number of substrings is width x number of substrings =< 250. Eg. max 25 of 10 character longs strings. Strings of less than width are right justified and padded with spaces. Routine returns with string$ set up as the holder with the width in character positions 1 and 2 (maximum 99) and a pointer to the bottom of the stack + 1 in positions 3, 4 and 5. S.QUEUE.PUSH string$,data$ Push data$ onto queue string$. If data$ is shorter than width, data$ is right justified and padded with spaces. S.QUEUE.PULL$(string$) Function to pop the bottom (first) substring off the queue string$. All string queue operations are checked for overflow, underflow or substrings too wide. List Operations --------------- S.LIST.CREATE string$,width Create a string as a holder for multiple substrings of width characters long for use as a random access list. Maximum number of substrings is width x number of substrings =< 250. Eg. max 25 of 10 character longs strings. Strings of less than width are right justified and padded with spaces. Routine returns with string$ set up as the holder with the width in character positions 1 and 2 (maximum 99) and a pointer to the bottom of the list + 1 in positions 3, 4 and 5. S.LIST.ADD string$,data$ Add data$ onto list string$ at the bottom. If data$ is shorter than width, data$ is right justified and padded with spaces. S.LIST.FILL string$,file$ Add data$ onto list string$ at the bottom from text file file$. Text file file$ must have each entry of length width or less and terminated with CRLF. CRLF is stripped prior to data$ being added to list. If data$ is shorter than width, data$ is right justified and padded with spaces. S.LIST.GET$(string$,index) Function to return the list entry pointed to by index. The list is not modified. All string list operations are checked for overflow or substrings too wide. ================================================================================ Commands for numeric manipulation in a stack. Numeric Operations ------------------ N.STACK.CREATE string$,width Create a string as a holder for multiple substrings of numeric variables for use as a Last In, First Out (LIFO) stack. Maximum number of numeric values pushed onto the stack is 62. Routine returns with string$ set up as the holder with the width in character positions 1 and 2 (always 4) and a pointer to the bottom of the stack + 1 in positions 3, 4 and 5. N.STACK.PUSH string$,data Push numeric data onto stack string$. N.STACK.POP(string$) Function to pop the top numeric value off the stack string$. N.STACK.AVERAGE(string$) Function to return the average of all the numerical values on the stack. All operations are checked for overflow, underflow or substrings too wide. Doug Pankhurst