Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 bad sort?
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
hey_joe42




PostPosted: 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
Sponsor
sponsor
Blade




PostPosted: Thu Mar 20, 2003 8:52 pm   Post subject: (No subject)

your open should be out of the loop
hey_joe42




PostPosted: 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




PostPosted: 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 Confused

posting your code is a good idea in situations like this Wink
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
hey_joe42




PostPosted: 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




PostPosted: 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 Confused

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.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 6 Posts ]
Jump to:   


Style:  
Search: