Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Resource Database Program
#1
For school my friend and I have been writing a database program to keep track of where the Year 7-8 resources are (500 textbooks). it is in JustBASIC ( a windows version of QB , google it  Big Grin) and it is almost finished but i want to organise from A-Z. what would be the fastest code to do that assuming the list is in an array?
WHILE RPG$ <> "complete" : make up silly excuses :WEND
Reply
#2
You want to use a shell or bubble sort.  A shell sort will be faster but a bubble sort is easier to code.  I in all honesty forget how to do them but you can easily figure out how to do them.  Basically A bubble sort works like this.


words: Cat, Dog, Apple, Justice, Health, Gatorade

It will compare Cat and Dog first

Cat vs. Dog no change cat starts with a c and c comes before d

Cat, Dog, Apple, Justice, Health, Gatorade

next dog vs. apple change a comes before d

Cat, Apple, Dog, Justice, Health, Gatorade

next dog vs. justice no change d comes before j

Cat, Apple, Dog, Justice, Health, Gatorade

next justice vs. health change h comes before j

Cat, Apple, Dog, Health, justice, Gatorade

next justice vs gatorade change g comes before j

Cat, Apple, Dog, Health, Gatorade, justice

And so on until the order no longer has any changes.  It will go through the list more than once (assuming nothing is in correct order)

I forget the logic on shell sort but it has something to do with splitting everything in half.

http://en.wikipedia.org/wiki/Bubble_sort

http://en.wikipedia.org/wiki/Shell_sort

Sorry about forgetting the algorithms to these but I haven't used QB in almost 4 months now but I hope this helps you to get started.
Reply
#3
thanks. I think i will use shell sort as it already takes 30 seconds to load and then teachers will probably get impatient.
WHILE RPG$ <> "complete" : make up silly excuses :WEND
Reply
#4
Glad I can get you started.  If I still had my QB book I'd post what basic shell sort code looks like but I don't.  You should be able to find more resources on the web as well.
Reply
#5
Quote:( a windows version of QB , google it  Big Grin )

A quick note  ;D

JB isnt a Windows version of QB, JB is it's own dialect of BASIC just like QB is its own dialect of BASIC. All versions of BASIC have evolved over time based on the original BASIC developed by John Kemeny and Thomas Kurtz at Dartmouth College.

Although the JB developers may have been influenced by QB, JB and QB are still considered different languages (under the same general scope of "BASIC" languages.)
-yah
Reply
#6
Well, here's one way (mentioned above).  It uses the QB command SWAP to put names in alphabetical order.  I don't *think* JB has a SWAP command, but could be wrong since It' been a while since I actually made somethiing with JB. (I was a beta tester for it, that was a while ago).

The QB way...

Quote:NumberOfEntries = 4  'how many names to sort

DIM Names(NumberOfEntries) AS STRING  'Make room for them

'Make up some names to use, not in order of course

Names(1) = "Nathan"
Names(2) = "Amy"
Names(3) = "Zimmy"
Names(4) = "Daniel"

'Let's see the order before sorting...

PRINT "=== Before Sorting ==="
FOR t% = 1 TO NumberOfEntries
   PRINT Names(t%)
NEXT

'Now let's put them in alphabetical order...

FOR y% = 1 TO NumberOfEntries
   FOR x% = y% TO NumberOfEntries
      IF Names(y%) > Names(x%) THEN
         SWAP Names(y%), Names(x%)
      END IF
   NEXT
NEXT

'Ok, that should have done it.
'Let's see the names in Alphabetical order

PRINT "=== After sorting ==="
FOR t% = 1 TO NumberOfEntries
   PRINT Names(t%)
NEXT

'-----------------------------
'END EXAMPLE
'-----------------------------

There's an article or two about sorting on the justbasic forum. Wait...here's a link...
http://justbasic.conforums.com/index.cgi...1120928790

- Dav
Reply
#7
(04-22-2008, 10:22 PM)zoasterboy link Wrote:
Quote:( a windows version of QB , google it  Big Grin )

A quick note  ;D

JB isnt a Windows version of QB ...
Sorry I meant it acts similarly to QB

LPG
WHILE RPG$ <> "complete" : make up silly excuses :WEND
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)