Created
August 31, 2014 16:52
-
-
Save ishankhare07/721d72377dd32836449d to your computer and use it in GitHub Desktop.
shortest job first algo
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from __future__ import print_function, division | |
import os | |
job_list = [] | |
id = 0 | |
def calc_wt(): | |
temp = [] | |
for x in job_list: | |
sum = 0 | |
for y in job_list[:job_list.index(x)]: | |
sum += y[0] | |
temp.append((x[1],sum)) | |
temp.sort() | |
for x in temp: | |
print('waiting time for process id', x[0],'is',x[1],sep=' ') | |
def calc_avg(): | |
temp = [x[0] for x in job_list] | |
print('Average waiting time is',sum(temp)/len(temp),sep=' : ') | |
def get_process(): | |
global id | |
os.system('clear') | |
process_time = int(raw_input('Enter process time')) | |
id += 1 | |
job_list.append((process_time,id)) | |
job_list.sort() | |
def show(): | |
os.system('clear') | |
for time,id in job_list: | |
print(id,time,sep=' ') | |
while 1: | |
print('1. Enter','2. Show','3. Display Waiting time','4. Average waiting time','5. Exit',sep='\n') | |
ch = int(raw_input()) | |
if ch == 1: | |
get_process() | |
elif ch == 2: | |
show() | |
elif ch == 3: | |
calc_wt() | |
elif ch == 4: | |
calc_avg() | |
elif ch == 5: | |
print('Exiting....') | |
exit() | |
else: | |
print('Wrong choice!!','Try again',sep='\n') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment