Implement the SCAN, C_SCAN, and LOOK disk scheduling algorithms in Java. Namely, the first command-line parameter must be the current head position. The list of cylinder requests must be read from the standard input, you can use input redirection for reading it from a file. In C Scan you need to go till end of disk that is 0 and 99 (if disk is end at 99) But in C Look we don't have to go end of disk, we just need to go till smallest given request and largest given request.
LOOK o Like SCAN except stops moving inwards (or outwards) when no more requests in that direction exist. C-SCAN (circular scan) o Moves inwards servicing requests until it arrive at the innermost cylinder then jumps to the outside cylinder of the disk without servicing any requests. O Replicate this over and over. O Variant service needs from inside to outside and then skip back to the innermost cylinder. C-LOOK o Moves inwards servicing needs until there are no more requests in that direction and then it jumps to the outermost outstanding requests. O Replicate this over and over.
O Variant service requirements from inside to outside after that skip back to the innermost request.
You are using C, but overall, your code looks like C. There are numerous ways to improve your code readability by replacing C standard features by C ones. I will give some examples. Using namespace std; Wirting using namespace std; is generally, especially when written in the global namesapce: it leads to potential name clashes and namespace pollution. You should just add std:: before every function/calss/variable from the standard library. Headers Several remarkes here:.
is a C header, in C, you should include instead, which is its C equivalent. is an old non-portable header. For input/output operations, you should generally use and stick with it. Also, it's good practice to organize your include directives in alphabetical ordering.
That helps to check whether some header has already been included or not, and to avoid including twice some header. Standard library collections Instead of using old C arrays and pointers, you can use standard library containers. For example, a fixed sized array int arr30 can be replaced by the equivalent std::array in C11 (this container is not directly available in the older versions of the standard). Standard library algorithms Instead of the old qsort, which requires to take a function pointer with void. pointers and do some ugly casts, you should use std::sort in the standard header.
It should be at least as fast (if not faster) and easier to read and write. You can replace this line: qsort(sortedrequest+1,numberofrequest,sizeof(int),compare); by this one: std::sort(std::begin(sortedrequest), std::end(sortedrequest)); Miscellaneous notes I can't cover all your code because it would have to be refactored to use more standard library features beforehand, but here are some notes:. Upper case names should only be used for preprocessor macros. Therefore, your functions CSCAN and LOOK (and the other ones) should be named cscan and look instead. I'm not at ease with using std::cin in the constructor of disk.
Such user interaction should not appear at construction, but be handled later by the client code of the class. if(direction=1) is probably a bug, it should be if(direction1), using proper compiler flags ( -Wall, -Wextra, etc.) should tell you when you use an assignment instead of a comparison in if. There is a typo in recieverequest: it should be receiverequest. Overall, you should really consider looking at the C standard library and using its classes and algorithms to replace many things in your code.