fork download
  1. // Algoritma PICK UP
  2. // Diketahui disk mempunyai 100 track dg nomor urut 0 99,
  3. // antrian akses track dengan saat awal 50 (letak head R/W)
  4. // 60 43 49 12 35 27 6 95 5 80 9 73 64 90 55 92
  5.  
  6. void main() {
  7. int initialTrack = 50;
  8. List<int> trackQueue = [
  9. 60,
  10. 43,
  11. 49,
  12. 12,
  13. 35,
  14. 27,
  15. 6,
  16. 95,
  17. 5,
  18. 80,
  19. 9,
  20. 73,
  21. 64,
  22. 90,
  23. 55,
  24. 92
  25. ];
  26.  
  27. List<int> pickUpQueue(List<int> queue) {
  28. // Insert initial tract to the queue
  29. queue.insert(0, initialTrack);
  30.  
  31. // Sort the queue to ascending order
  32. queue.sort();
  33.  
  34. var highestQueue = queue.where((test) => test > initialTrack);
  35. var lowesQueue =
  36. queue.where((test) => test < initialTrack).toList().reversed;
  37.  
  38. return [...highestQueue, ...lowesQueue];
  39. }
  40.  
  41. List<int> pickedUpQueue = pickUpQueue(trackQueue);
  42. print('Picked Up Queue: ${pickedUpQueue.join(' -> ')}');
  43. }
  44.  
Success #stdin #stdout 1.1s 120320KB
stdin
Standard input is empty
stdout
Standard output is empty