here’s my dilema.
I have for example this string:
“1 2 3 4 5 ….. 100” , but it can be any length (usually much, much bigger one, talking about 4 digit numbers).
What I need to do: re-arrange the elements of the string based on a known possition.
E.g: the position in question is 70. I need to have the following output:
“70 71 ….100 1 2 3 …69”
Conditions:
- I know the key: e.g the above “70”. Can be also 500, 5000, depends on the string length.
- I can’t use any string buffers or string management functions.
- There’s little to none memory available.
- There are two 1 byte buffers available.
- Operation should be done in with the least possible steps (time critical).
I’ve been trying to find a good algorithm that would not depend on the position of key in the string. Basically shifting left/right depending on what half I am still makes it for a lot of reads/writes and I don’t want that.
Thanks a lot!
this code fits your decription, but you’ve been vague enough that I doubt it does what you want…
Produces the following output:
But should work just the same for sequences all the way up to
9999