T
T
tsovak2014-12-20 16:43:02
binary code
tsovak, 2014-12-20 16:43:02

How to move an element to the beginning of a binary file?

Vwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Don Kaban, 2014-12-20
@donkaban

-- There was a wrong comment here, I read problem
1 inaccurately. Sucking the entire file into memory doesn't work even for lab work. If possible, the task is not a task at all.
2. I would read the file once, remember the seek_pos for the minimum, and write everything to a new file in a second pass. It's 2N, bad but not fatal.
3. The code from the OP is a wild impenetrable forest, disgusting even for a humanities student
4. N*LogN can be obtained in chunks, but the code will get confused, which is not very good for a lab.

A
Armenian Radio, 2014-12-20
@gbg

Why do you have memory allocated under int, and bytes of size double are read?
Why do you have a rotten pascal style with allocating variables somewhere far at the beginning of the program and using them? Why didn't you declare the i variable in the loop header?
Why are you using functions from the C standard library (fopen, fwrite, ...) even though you write in C++?
Why are you moving the pointer to the beginning of the file immediately after opening? Immediately after the opening, the pointer already stands at the beginning.
In the form that you have done, you can do all the operations in memory by displaying the file.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question