Disk Scheduling (LOOK)

easy · os, storage, scheduling

Disk Scheduling (LOOK)

Simulate the LOOK disk scheduling algorithm.

Types

type DiskResult struct {
    Order []int
    Seek  int
}

func ScheduleLOOK(head int, dir int, requests []int) DiskResult

Rules

  • head is the current head position.
  • dir is the initial direction: 1 for increasing tracks, -1 for decreasing.
  • LOOK services all requests in the current direction (sorted), then reverses.
  • The head does not go to the end of the disk, only as far as the last request.

Output

  • Order: the sequence of serviced requests.
  • Seek: total head movement (sum of absolute deltas).

Notes

  • If requests is empty, return empty order and zero seek.
Run tests to see results
No issues detected