How to resolve the algorithm Sort an array of composite structures step by step in the Run BASIC programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Sort an array of composite structures step by step in the Run BASIC programming language

Table of Contents

Problem Statement

Sort an array of composite structures by a key.

For example, if you define a composite structure that presents a name-value pair (in pseudo-code): and an array of such pairs: then define a sort routine that sorts the array x by the key name. This task can always be accomplished with Sorting Using a Custom Comparator. If your language is not listed here, please see the other article.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Sort an array of composite structures step by step in the Run BASIC programming language

Source code in the run programming language

sqliteconnect #mem, ":memory:"                          ' create in memory db
mem$	= "CREATE TABLE people(num integer, name text,city text)"
#mem execute(mem$)
data "1","George","Redding","2","Fred","Oregon","3","Ben","Seneca","4","Steve","Fargo","5","Frank","Houston"

for i = 1 to 5                                          ' read data and place in memory DB
 read num$ :read name$: read city$
 #mem execute("INSERT INTO people VALUES(";num$;",'";name$;"','";city$;"')")
next i
#mem execute("SELECT * FROM people ORDER BY name")      'sort by name order
WHILE  #mem hasanswer()
  #row  = #mem #nextrow()
  num   = #row num()
  name$	= #row name$()
  city$	= #row city$()
  print num;" ";name$;" ";city$
WEND

  

You may also check:How to resolve the algorithm Ascending primes step by step in the V (Vlang) programming language
You may also check:How to resolve the algorithm Function composition step by step in the J programming language
You may also check:How to resolve the algorithm Multiplication tables step by step in the Ring programming language
You may also check:How to resolve the algorithm Almkvist-Giullera formula for pi step by step in the Raku programming language
You may also check:How to resolve the algorithm Recaman's sequence step by step in the Julia programming language