mohd sherrez wrote:Hi i am currently making some disk alogrithms and need some help( i managed to do SSTF ,FCFS and SCAN)
I have two problems
1.firstly i would like to change my scan alogrithm to work with my inward movement going away from zero ( i have supplied my code for scan for movement towards zero anybody could help me convert it?)
First: This sounds like a very specific problem area, so I'm not sure how much help you'll get in a "general" forum. However, I'm not sure if there's any better place to put it.
Second: Please
UseCodeTags (←click) when posting code. I've added them this time - see how much better it looks?
And please read the part about
not writing long lines. You're fine at the moment, but they can really screw up the window formatting here if you do.
2.Secondly i have no idea how to implement c-scan,Look or c-look alogrithms in java could you guys help?
Yes, but only generally, because I've never tried to implement that algorithm myself.
However, just from what I see:
1. You could help yourself (and us) out a lot by giving your fields better names. '
temp', for example doesn't tell us anything; but '
sorted' does.
2. You use
Arrays.sort() to sort your array, but you don't use any of its other methods (eg,
copyOf() and
binarySearch()) which might be useful for you. Just as an example:
int temp[] = Arrays.sort( Arrays.copyOf(sequence, sequence.length+1) );
int scan[] = new int[temp.length];
is
precisely equivalent to your lines 4-11.
(your '
temp[n] = 0' statement is redundant because
int array elements are always initialized to '0')
3. I'm not quite sure why you need that extra '0' in your array (which will be "sorted" into whatever position is appropriate when you run
Arrays.sort()), so it might be worth explaining it to anyone else who needs to read your code.
4. You don't appear to allow for the fact that either NO element in '
temp' is less than '
current', or ALL of them are; both of which I suspect are exceptions (although not necessarily errors). I suspect you could also do the same thing (and a lot quicker) with
binarySearch().
5. That last part of the algorithm needs a bit of explaining. It's fine for you, since you've probably been reading about it for many hours; but for anyone looking at your code (like me), it's a complete mystery what you're trying to do.
HIH
Winston