Skip to content

Commit 069fdac

Browse files
committed
Update code
1 parent 2fe1a2a commit 069fdac

File tree

3 files changed

+9
-8
lines changed

3 files changed

+9
-8
lines changed

src/main/java/com/thealgorithms/scheduling/diskscheduling/CircularScanScheduling.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public List<Integer> execute(List<Integer> requests) {
3737
if (movingUp) {
3838
// Moving up: process requests >= current position
3939
for (int request : sortedRequests) {
40-
if (request >= currentPosition) {
40+
if (request >= currentPosition && request < diskSize) {
4141
result.add(request);
4242
}
4343
}

src/main/java/com/thealgorithms/scheduling/diskscheduling/LookScheduling.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@
1111
* and once it processes all requests in that direction, it reverses the direction.
1212
*/
1313
public class LookScheduling {
14-
1514
private final int maxTrack;
1615
private final int currentPosition;
1716
private boolean movingUp;
1817
private int farthestPosition;
1918

19+
2020
public LookScheduling(int startPosition, boolean initialDirection, int maxTrack) {
2121
this.currentPosition = startPosition;
2222
this.movingUp = initialDirection;
@@ -36,10 +36,12 @@ public List<Integer> execute(List<Integer> requests) {
3636

3737
// Split requests into two lists based on their position relative to current position
3838
for (int request : requests) {
39-
if (request < currentPosition) {
40-
lower.add(request);
41-
} else {
42-
upper.add(request);
39+
if (request >= 0 && request < maxTrack) {
40+
if (request < currentPosition) {
41+
lower.add(request);
42+
} else {
43+
upper.add(request);
44+
}
4345
}
4446
}
4547

src/test/java/com/thealgorithms/scheduling/diskscheduling/SSFSchedulingTest.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,5 +52,4 @@ public void testGetCurrentPositionAfterExecution() {
5252
int currentPosition = scheduler.getCurrentPosition();
5353
assertEquals(10, currentPosition, "Current position should be the last request after execution.");
5454
}
55-
56-
}
55+
}

0 commit comments

Comments
 (0)