FCFS Disk Scheduling Algorithm

Here given code implementation process.

// C program
// FCFS Disk Scheduling Algorithm 
#include <stdio.h>

//Implement FCFS disk scheduling algorithm
void fcfs_disk_scheduling(int queue[], int head, int n)
{
	//Resultant variable which are used to store information of number of time or operation
	double seek_time = 0.0;
	int distance = 0;
	// Loop controlling variable
	int i = 0;
  
  	printf("\n Starting Head : %d ", head);
	printf("\n Queue Sequence : ");
	//Display given queue elements
	for (i = 0; i < n; i++)
	{
		printf("  %d", queue[i]);
	}
	
	for (i = 0; i < n; i++)
	{
		//Get distance 
		distance = queue[i] - head;
		if (distance < 0)
		{
			//When distance is negative then convert into it absolute value
			distance = -distance;
		}
		// Update head data into current track value
		head = queue[i];
		// Add current distance into seek
		seek_time += distance;
	}
	//Display result
	printf("\n Total Seek Time   : %lf", seek_time);
	printf("\n Average Seek Time : %lf\n", seek_time / n);
}
int main()
{
	// Request queue elements
	int queue[] = {
		64,
		12,
		42,
		19,
		62,
		32,
		16,
		86
	};
	//Get the number of elements in request queue
	int n = sizeof(queue) / sizeof(queue[0]);
	//Initial head position
	int head = 25;
	fcfs_disk_scheduling(queue, head, n);
	return 0;
}

Output

 Starting Head : 25
 Queue Sequence :   64  12  42  19  62  32  16  86
 Total Seek Time   : 303.000000
 Average Seek Time : 37.875000
// Java program 
// FCFS Disk Scheduling Algorithm 
class FcfsScheduling
{
	//Implement FCFS disk scheduling algorithm
	public void fcfs_disk_scheduling(int[] queue, int head, int n)
	{
		//Resultant variable which are used to store information of number of time or operation
		double seek_time = 0.0;
		int distance = 0;
		// Loop controlling variable
		int i = 0;
		System.out.print("\n Starting Head : " + head);
		System.out.print("\n Queue Sequence : ");
		//Display given queue elements
		for (i = 0; i < n; i++)
		{
			System.out.print(" " + queue[i] + "");
		}
		for (i = 0; i < n; i++)
		{
			//Get distance 
			distance = queue[i] - head;
			if (distance < 0)
			{
				//When distance is negative then convert into it absolute value
				distance = -distance;
			}
			// Update head data into current track value
			head = queue[i];
			// Add current distance into seek
			seek_time += distance;
		}
		//Display result
		System.out.print("\n Total Seek Time : " + seek_time);
		System.out.print("\n Average Seek Time : " + seek_time / n + "\n");
	}
	public static void main(String args[])
	{
		FcfsScheduling obj = new FcfsScheduling();
		// Request queue elements
		int[] queue = {
			64,
			12,
			42,
			19,
			62,
			32,
			16,
			86
		};
		//Get the number of elements in request queue
		int n = queue.length;
		//Initial head position
		int head = 25;
		obj.fcfs_disk_scheduling(queue, head, n);
	}
}

Output

 Starting Head : 25
 Queue Sequence :  64 12 42 19 62 32 16 86
 Total Seek Time : 303.0
 Average Seek Time : 37.875
//Include header file
#include <iostream>
using namespace std;

// C++ program 
// FCFS Disk Scheduling Algorithm 

class FcfsScheduling
{
	public:
		//Implement FCFS disk scheduling algorithm
		void fcfs_disk_scheduling(int queue[], int head, int n)
		{
			//Resultant variable which are used to store information of number of time or operation
			double seek_time = 0.0;
			int distance = 0;
			// Loop controlling variable
			int i = 0;
			cout << "\n Starting Head : " << head;
			cout << "\n Queue Sequence : ";
			//Display given queue elements
			for (i = 0; i < n; i++)
			{
				cout << " " << queue[i] << "";
			}
			for (i = 0; i < n; i++)
			{
				//Get distance 
				distance = queue[i] - head;
				if (distance < 0)
				{
					//When distance is negative then convert into it absolute value
					distance = -distance;
				}
				// Update head data into current track value
				head = queue[i];
				// Add current distance into seek
				seek_time += distance;
			}
			//Display result
			cout << "\n Total Seek Time : " << seek_time;
			cout << "\n Average Seek Time : " << seek_time / n << "\n";
		}
};
int main()
{
	FcfsScheduling obj = FcfsScheduling();
	// Request queue elements
	int queue[] = {
		64 , 12 , 42 , 19 , 62 , 32 , 16 , 86
	};
	//Get the number of elements in request queue
	int n = sizeof(queue) / sizeof(queue[0]);
	//Initial head position
	int head = 25;
	obj.fcfs_disk_scheduling(queue, head, n);
	return 0;
}

Output

 Starting Head : 25
 Queue Sequence :  64 12 42 19 62 32 16 86
 Total Seek Time : 303
 Average Seek Time : 37.875
//Include namespace system
using System;
// C# program 
// FCFS Disk Scheduling Algorithm 
class FcfsScheduling
{
	//Implement FCFS disk scheduling algorithm
	public void fcfs_disk_scheduling(int[] queue, int head, int n)
	{
		//Resultant variable which are used to store information of number of time or operation
		double seek_time = 0.0;
		int distance = 0;
		// Loop controlling variable
		int i = 0;
		Console.Write("\n Starting Head : " + head);
		Console.Write("\n Queue Sequence : ");
		//Display given queue elements
		for (i = 0; i < n; i++)
		{
			Console.Write(" " + queue[i] + "");
		}
		for (i = 0; i < n; i++)
		{
			//Get distance 
			distance = queue[i] - head;
			if (distance < 0)
			{
				//When distance is negative then convert into it absolute value
				distance = -distance;
			}
			// Update head data into current track value
			head = queue[i];
			// Add current distance into seek
			seek_time += distance;
		}
		//Display result
		Console.Write("\n Total Seek Time : " + seek_time);
		Console.Write("\n Average Seek Time : " + seek_time / n + "\n");
	}
	public static void Main(String []args)
	{
		FcfsScheduling obj = new FcfsScheduling();
		// Request queue elements
		int[] queue = {
			64 , 12 , 42 , 19 , 62 , 32 , 16 , 86
		};
		//Get the number of elements in request queue
		int n = queue.Length;
		//Initial head position
		int head = 25;
		obj.fcfs_disk_scheduling(queue, head, n);
	}
}

Output

 Starting Head : 25
 Queue Sequence :  64 12 42 19 62 32 16 86
 Total Seek Time : 303
 Average Seek Time : 37.875
<?php
// Php program 
// FCFS Disk Scheduling Algorithm 
class FcfsScheduling
{
	//Implement FCFS disk scheduling algorithm
	public	function fcfs_disk_scheduling( & $queue, $head, $n)
	{
		//Resultant variable which are used to store information of number of time or operation
		$seek_time = 0.0;
		$distance = 0;
		// Loop controlling variable
		$i = 0;
		echo "\n Starting Head : ". $head;
		echo "\n Queue Sequence : ";
		//Display given queue elements
		for ($i = 0; $i < $n; $i++)
		{
			echo " ". $queue[$i] ."";
		}
		for ($i = 0; $i < $n; $i++)
		{
			//Get distance 
			$distance = $queue[$i] - $head;
			if ($distance < 0)
			{
				//When distance is negative then convert into it absolute value
				$distance = -$distance;
			}
			// Update head data into current track value
			$head = $queue[$i];
			// Add current distance into seek
			$seek_time += $distance;
		}
		//Display result
		echo "\n Total Seek Time : ". $seek_time;
		echo "\n Average Seek Time : ". ($seek_time / $n) ."\n";
	}
}

function main()
{
	$obj = new FcfsScheduling();
	// Request queue elements
	$queue = array(64, 12, 42, 19, 62, 32, 16, 86);
	//Get the number of elements in request queue
	$n = count($queue);
	//Initial head position
	$head = 25;
	$obj->fcfs_disk_scheduling($queue, $head, $n);
}
main();

Output

 Starting Head : 25
 Queue Sequence :  64 12 42 19 62 32 16 86
 Total Seek Time : 303
 Average Seek Time : 37.875
// Node Js program 
// FCFS Disk Scheduling Algorithm 
class FcfsScheduling
{
	//Implement FCFS disk scheduling algorithm
	fcfs_disk_scheduling(queue, head, n)
	{
		//Resultant variable which are used to store information of number of time or operation
		var seek_time = 0.0;
		var distance = 0;
		// Loop controlling variable
		var i = 0;
		process.stdout.write("\n Starting Head : " + head);
		process.stdout.write("\n Queue Sequence : ");
		//Display given queue elements
		for (i = 0; i < n; i++)
		{
			process.stdout.write(" " + queue[i] + "");
		}
		for (i = 0; i < n; i++)
		{
			//Get distance 
			distance = queue[i] - head;
			if (distance < 0)
			{
				//When distance is negative then convert into it absolute value
				distance = -distance;
			}
			// Update head data into current track value
			head = queue[i];
			// Add current distance into seek
			seek_time += distance;
		}
		//Display result
		process.stdout.write("\n Total Seek Time : " + seek_time);
		process.stdout.write("\n Average Seek Time : " + (seek_time / n) + "\n");
	}
}

function main()
{
	var obj = new FcfsScheduling();
	// Request queue elements
	var queue = [64, 12, 42, 19, 62, 32, 16, 86];
	//Get the number of elements in request queue
	var n = queue.length;
	//Initial head position
	var head = 25;
	obj.fcfs_disk_scheduling(queue, head, n);
}
main();

Output

 Starting Head : 25
 Queue Sequence :  64 12 42 19 62 32 16 86
 Total Seek Time : 303
 Average Seek Time : 37.875
#  Python 3 program 
#  FCFS Disk Scheduling Algorithm 

class FcfsScheduling :
	# Implement FCFS disk scheduling algorithm
	def fcfs_disk_scheduling(self, queue, head, n) :
		# Resultant variable which are used to store information of number of time or operation
		seek_time = 0.0
		distance = 0
		#  Loop controlling variable
		i = 0
		print("\n Starting Head : ", head, end = "")
		print("\n Queue Sequence : ", end = "")
		# Display given queue elements
		while (i < n) :
			print(" ", queue[i], end = "")
			i += 1
		
		i = 0
		while (i < n) :
			# Get distance 
			distance = queue[i] - head
			if (distance < 0) :
				# When distance is negative then convert into it absolute value
				distance = -distance
			
			#  Update head data into current track value
			head = queue[i]
			#  Add current distance into seek
			seek_time += distance
			i += 1
		
		# Display result
		print("\n Total Seek Time : ", seek_time, end = "")
		print("\n Average Seek Time : ", seek_time / n ,"\n", end = "")
	

def main() :
	obj = FcfsScheduling()
	#  Request queue elements
	queue = [64, 12, 42, 19, 62, 32, 16, 86]
	# Get the number of elements in request queue
	n = len(queue)
	# Initial head position
	head = 25
	obj.fcfs_disk_scheduling(queue, head, n)

if __name__ == "__main__": main()

Output

 Starting Head :  25
 Queue Sequence :   64  12  42  19  62  32  16  86
 Total Seek Time :  303.0
 Average Seek Time :  37.875
#  Ruby program 
#  FCFS Disk Scheduling Algorithm 
class FcfsScheduling

	# Implement FCFS disk scheduling algorithm
	def fcfs_disk_scheduling(queue, head, n)
	
		# Resultant variable which are used to store information of number of time or operation
		seek_time = 0.0
		distance = 0
		#  Loop controlling variable
		i = 0
		print("\n Starting Head : ", head)
		print("\n Queue Sequence : ")
		# Display given queue elements
		while (i < n)
		
			print(" ", queue[i])
			i += 1
		end
		i = 0
		while (i < n)
		
			# Get distance 
			distance = queue[i] - head
			if (distance < 0)
			
				# When distance is negative then convert into it absolute value
				distance = -distance
			end
			#  Update head data into current track value
			head = queue[i]
			#  Add current distance into seek
			seek_time += distance
			i += 1
		end
		# Display result
		print("\n Total Seek Time : ", seek_time)
		print("\n Average Seek Time : ", seek_time / n ,"\n")
	end
end
def main()

	obj = FcfsScheduling.new()
	#  Request queue elements
	queue = [64, 12, 42, 19, 62, 32, 16, 86]
	# Get the number of elements in request queue
	n = queue.length
	# Initial head position
	head = 25
	obj.fcfs_disk_scheduling(queue, head, n)
end
main()

Output

 Starting Head : 25
 Queue Sequence :  64 12 42 19 62 32 16 86
 Total Seek Time : 303.0
 Average Seek Time : 37.875
// Scala program 
// FCFS Disk Scheduling Algorithm 
class FcfsScheduling
{
	//Implement FCFS disk scheduling algorithm
	def fcfs_disk_scheduling(queue: Array[Int], h: Int, n: Int): Unit = {
		//Resultant variable which are used to store information of number of time or operation
		var seek_time: Double = 0.0;
		var distance: Int = 0;
		// Loop controlling variable
		var i: Int = 0;
      	var head = h;
		print("\n Starting Head : " + head);
		print("\n Queue Sequence : ");
		//Display given queue elements
		while (i < n)
		{
			print(" " + queue(i));
			i += 1;
		}
		i = 0;
		while (i < n)
		{
			//Get distance 
			distance = queue(i) - head;
			if (distance < 0)
			{
				//When distance is negative then convert into it absolute value
				distance = -distance;
			}
			// Update head data into current track value
			head = queue(i);
			// Add current distance into seek
			seek_time += distance;
			i += 1;
		}
		//Display result
		print("\n Total Seek Time : " + seek_time);
		print("\n Average Seek Time : " + (seek_time / n) + "\n");
	}
}
object Main
{
	def main(args: Array[String]): Unit = {
		var obj: FcfsScheduling = new FcfsScheduling();
		// Request queue elements
		var queue: Array[Int] = Array(64, 12, 42, 19, 62, 32, 16, 86);
		//Get the number of elements in request queue
		var n: Int = queue.length;
		//Initial head position
		var head: Int = 25;
		obj.fcfs_disk_scheduling(queue, head, n);
	}
}

Output

 Starting Head : 25
 Queue Sequence :  64 12 42 19 62 32 16 86
 Total Seek Time : 303.0
 Average Seek Time : 37.875
// Swift program 
// FCFS Disk Scheduling Algorithm 
class FcfsScheduling
{
	//Implement FCFS disk scheduling algorithm
	func fcfs_disk_scheduling(_ queue: [Int], _ head: inout Int, _ n: Int)
	{
		//Resultant variable which are used to store information of number of time or operation
		var seek_time: Double = 0.0;
		var distance: Int = 0;
		// Loop controlling variable
		var i: Int = 0;
		print("\n Starting Head : ", head, terminator: "");
		print("\n Queue Sequence : ", terminator: "");
		//Display given queue elements
		while (i < n)
		{
			print(" ", queue[i], terminator: "");
			i += 1;
		}
		i = 0;
		while (i < n)
		{
			//Get distance 
			distance = queue[i] - head;
			if (distance < 0)
			{
				//When distance is negative then convert into it absolute value
				distance = -distance;
			}
			// Update head data into current track value
			head = queue[i];
			// Add current distance into seek
			seek_time += Double(distance);
			i += 1;
		}
		//Display result
		print("\n Total Seek Time : ", seek_time, terminator: "");
		print("\n Average Seek Time : ", seek_time / Double(n) );
	}
}
func main()
{
	let obj: FcfsScheduling = FcfsScheduling();
	// Request queue elements
	let queue: [Int] = [64, 12, 42, 19, 62, 32, 16, 86];
	//Get the number of elements in request queue
	let n: Int = queue.count;
	//Initial head position
	var head: Int = 25;
	obj.fcfs_disk_scheduling(queue, &head, n);
}
main();

Output

 Starting Head :  25
 Queue Sequence :   64  12  42  19  62  32  16  86
 Total Seek Time :  303.0
 Average Seek Time :  37.875


Please share your knowledge to improve code and content standard. Also submit your doubts, and test case. We improve by your feedback. We will try to resolve your query as soon as possible.

New Comment







© 2021, kalkicode.com, All rights reserved