bad sort?
Author |
Message |
hey_joe42
|
Posted: Thu Mar 20, 2003 8:51 pm Post subject: bad sort? |
|
|
there something that seems wrong with my sort can anyone pinpoint it, like it should work
it using records
code: |
count := 0
loop
open : fn, "inventory1.bin", read, seek
exit when eof (fn)
seek:fn,count*sizeof(inventory)
exit when eof (fn)
count += 1
put count
read : fn, prod
read : fn, prod2
put prod.manufacturer, ":", prod2.manufacturer
delay (1000)
if prod.manufacturer > prod2.manufacturer then
temp := prod
prod := prod2
prod2 := temp
end if
close : fn
open : fn, "inventory1.bin", write, mod, seek
put (count-1)*sizeof(inventory)
delay(2000)
seek : fn, (count - 1) * sizeof (inventory)
write : fn, prod, prod2
close:fn
end loop |
|
|
|
|
|
|
Sponsor Sponsor
|
|
|
Blade
|
Posted: Thu Mar 20, 2003 8:52 pm Post subject: (No subject) |
|
|
your open should be out of the loop |
|
|
|
|
|
hey_joe42
|
Posted: Thu Mar 20, 2003 9:48 pm Post subject: (No subject) |
|
|
This sort just doesn't work how would you do a sort using records
k
i want to do a bubble sort, for records in binary file but for some reason mine doesn't work so i was wondering if anyone could take a try for me with what should work
k the records are prod, prod2 and temp%temp file
and well just do a sort for the products so it be
prod.product and prod2.product
for somereason my above not only doesn't work doesn't exit? whatever's up with that
and unless you guys have a tutorial for binary files and records of bubble sort, prolly another tutorial won't work since i know how to do a bubble sort |
|
|
|
|
|
Tony
|
Posted: Thu Mar 20, 2003 10:11 pm Post subject: (No subject) |
|
|
what you mean it doesnt exit? bubble sort's suppost to be 2 forloops
posting your code is a good idea in situations like this |
Tony's programming blog. DWITE - a programming contest. |
|
|
|
|
hey_joe42
|
Posted: Thu Mar 20, 2003 10:18 pm Post subject: (No subject) |
|
|
ooo whoops good point, my bubble sort is all wrong then, but still how would you do two loops like i have my code posted on the topic msg,
but k how do i make it in to a bubble sort, how would i go about making two for loops for this cuz there not arrays |
|
|
|
|
|
Tony
|
Posted: Thu Mar 20, 2003 10:29 pm Post subject: (No subject) |
|
|
1st of all, get rid of delays... I donno why you would stick a delay in a sort
2nd read your info into an array... with bubble sort, you'd have to compare and rewrite the order a LOT. Reading through the whole file each time is not very efficient since harddrive is much, much SLOWER then memory.
you can declear an array of custom type, and then sort comparing just 1 value in the record.
You should rewrite your program to work with the array instead of files, load info into an array at the start of the program and save back to a file at the end of it (or after permament action such as addition or deletion of a record).
Operation such as a sort should not be writen to the file. |
Tony's programming blog. DWITE - a programming contest. |
|
|
|
|
|
|