Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

BUBBLE FORMAT

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
I need to make a program for QBASIC where the user can input any 4 random numbers and the program will put the numbers in order from least to greatest. I would like ot do this using the bubble format.
 
I made a couple bubble sorts 5 years ago but I can't remember exactly how its done. Here is a very crude version, a bubble sort I think works faster by switching numbers in a way that shortens the list more effectively as you go.. This is all you need for four numbers...

TYPE R
NUM as INTEGER
END TYPE

DIM SEQ(1 to 4) AS R
offset=1


Input four numbers:

FOR I = 1 to 4
INPUT "Number?",seq(i).num
NEXT i

FOR Y = 1 to 4

FOR I = offset to 4
if x > seq(i).num then x=seq(i).num 'this will put the
f=i 'lowest number in x and store its index position in f
ENDIF 'if the number you read is greater than the last lowest number then it just goes on to the next

NEXT i

'now you have the first lowest number so put it at
the top of the list


temp = seq(offset).num 'store current top number in temp variable

'switch your low number with this
seq(offset).num = x

seq(f).num =temp ' this puts the number that was at the top where your low number was found

'I think bubble sorts make the best guess as to where to put this number, this just switches them

offset = offset + 1 ' add one to the offset so you don't look at numbers you've already sorted

x=0

NEXT Y ' does this 4 times















 
yeah yeah yeah.... its sorts from greatest to lowest hehe.... well that should be a clue for him anyway.
 
this didnot help much can you give me a clearer version with no TYPE and no DIM statements??
 
Actually, student16,

The information that hardcore100110 gave to you is the most effecient way of processing the data.

Otherwise, you'll have to deal with saving the data to an OutPut file.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top