Qbasic Program To Sort Numbers

HomePage | Optical Illusions | War Stories | QBasic | Dads Navy Days | Bristol | Bristol, USA | Bristol, Canada | Terre Haute | Miscellany | Web Stuff | About Ray | Site Map | Site Search | Messages | Credits | Links | Web Rings

And QBASIC will read this and print 'One Three Two ', as opposed to 'One Two Three'. So is there any batch file, or QB code that I can use to sort the line numbers of my generated BAS files? I would greatly appreciate the help! Thanks in advance, Komaru. Factorial of Number in C-Programming; Sum of Natural Numbers in C-Programming; Even or Odd in C program; CLASS 12 NOTES- COMMING SOON; Check Whether a number is positive, negative or zero in C program; Check Whether a Number is Armstrong or Not in C Program; Check Whether a Number is Palindrome or Not in C Program; String Pattern in QBasic.

QBasic | Errors | 40lb Weight | Bits | Chance | Colours | Dates | Delays | File Dialog | Files | Input | Matching | Menus | Mouse | Numbers | SeqNo | SIRDS | Sorts | Text | Timer | DLoads

Sortation techniques :-

Being able to sort items by size is an important part of computing. It is also, perhaps one of the less easily understood routines. Some simple sort routines are very slow whilst others seem too arcane to be understood by mere mortals - or by me at least.

Whilst trawling through my back copies of PC Plus - one of the magazines I subscribe to, I found a very fast sortation method. The next day someone gave me a copy of a program called SortDemo which was lurking on the disks of one of our older machines. I have no idea who wrote it, or how we came to have a copy but I have included it in the downloadable zip file. It was investigating these routines that I made the logic error you can read about in Errors.

Here are the timings when I ran this program at home :-

Technique

Time
(Seconds)

Insertion

57

Bubble

51

Heap

24

Exchange

18

Shell

14

Quick

9

Quicksort :-

From the table you can see the quickest by far was the QuickSort routine. Here's a program that generates an array of random numbers then sorts them using a QuickSort algorithm.

Sort

Screenshot of QSort.bas

Qbasic Program To Sort Numbers Worksheet

You can also sort a string array using this method. To do this you need to make all references to MyArray, SortArray and Partition into strings.

Bubblesort :-

One of the easiest sorts to write is the bubble sort. All this does is use two loops to compare every element of an array with every other element. If one element is bigger than the other it swaps them. for comparing short arrays it's good enough, but because of the number of comparisons it has to do, it's not really suitable for large arrays.

When you are writing and testing these sortation routines you'll need some test files to feed into the arrays. Here's a program that writes five of them. One is a file that is completely sorted, then sorted but 'upsidedown', one with the largest numbers at the top, another with the smallest at the bottom and finally a completely random one. I originally wrote this program a couple of years ago, and surprisingly, it still works. Who says I only write WORM programs? In this case WORM stands for Works Once - Rewrites Many.

To make the program run properly you'll need to edit the FilePath$ variable to a directory on your own drive. You can also control how many lines are produced by changing the number of elements in the NumArray array.

Qbasic Program To Sort Numbers Printable

The programs on this page, like all the programs written for this site, can be downloaded from the DLoads page.

QBasic | Errors | 40lb Weight | Bits | Chance | Colours | Dates | Delays | File Dialog | Files | Input | Matching | Menus | Mouse | Numbers | SeqNo | SIRDS | Sorts | Text | Timer | DLoads

HomePage | Optical Illusions | War Stories | QBasic | Dads Navy Days | Bristol | Bristol, USA | Bristol, Canada | Terre Haute | Miscellany | Web Stuff | About Ray | Site Map | Site Search | Messages | Credits | Links | Web Rings

Qbasic Program To Sort Numbers Anchor Chart


GoStats stats counter