Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Arrays;
- import java.util.Collections;
- import java.util.LinkedList;
- class process implements Comparable<process>{
- String ime;
- int vreme;
- int doagja;
- boolean gotov = false;
- boolean staven = false;
- process(String ime, int vreme, int doagja){
- this.ime = ime;
- this.vreme = vreme;
- this.doagja = doagja;
- }
- @Override
- public int compareTo(process o) {
- if(this.vreme > o.vreme) return 1;
- else if(this.vreme < o.vreme) return -1;
- else
- return 0;
- }
- }
- public class os {
- public static void main(String[] args) {
- LinkedList<process> lista = new LinkedList<process>();
- lista.add(new process("proc 1", 3, 0));
- lista.add(new process("proc 2", 4, 0));
- lista.add(new process("proc 3", 5, 0));
- lista.add(new process("proc 4", 1, 1));
- srtn(lista);
- lista = new LinkedList<process>();
- lista.add(new process("proc 1", 3, 0));
- lista.add(new process("proc 2", 4, 0));
- lista.add(new process("proc 3", 5, 0));
- lista.add(new process("proc 4", 1, 1));
- rr(lista);
- }
- public static void srtn(LinkedList<process> lista){
- System.out.println("SRTN");
- LinkedList<process> tmp = new LinkedList<process>();
- int gotovi = 0;
- int sega = 0;
- int cel = lista.size();
- while(gotovi < cel){
- tmp = new LinkedList<process>();
- for(int i=0;i<lista.size();i++){
- if(!lista.get(i).gotov && sega>=lista.get(i).doagja){
- tmp.add(lista.get(i));
- }
- }
- if(!tmp.isEmpty()){
- Collections.sort(tmp);
- String najm = tmp.get(0).ime;
- System.out.println(najm);
- for(int i=0;i<lista.size();i++){
- if(lista.get(i).ime.equals(najm)){
- lista.get(i).vreme--;
- if (lista.get(i).vreme==0)
- {
- lista.get(i).gotov=true;
- gotovi++;
- }
- }
- }
- }
- sega++;
- }
- }
- public static void rr(LinkedList<process> lista){
- int kvantum = 1;
- System.out.println();
- System.out.println();
- System.out.println("RR so kvantum " + kvantum);
- int gotovi = 0;
- int sega = 0;
- int cel = lista.size();
- LinkedList<process> tmp;
- tmp = new LinkedList<process>();
- for(int i=0;i<lista.size();i++){
- if(!lista.get(i).gotov && !lista.get(i).staven && sega>=lista.get(i).doagja){
- lista.get(i).staven = true;
- tmp.add(lista.get(i));
- System.out.println("dodadov " + lista.get(i).ime);
- }
- }
- while(gotovi<cel){
- for(int i=0;i<lista.size();i++){
- if(!lista.get(i).gotov && !lista.get(i).staven && sega>=lista.get(i).doagja){
- lista.get(i).staven = true;
- tmp.add(lista.get(i));
- System.out.println("dodadov " + lista.get(i).ime);
- }
- }
- if(!tmp.isEmpty()){
- System.out.println(tmp.get(0).ime);
- tmp.get(0).vreme-=kvantum;
- if(tmp.get(0).vreme<=0)
- {tmp.remove(tmp.get(0));
- gotovi++;
- }
- else{
- process temp = tmp.get(0);
- tmp.remove(tmp.get(0));
- tmp.add(temp);
- }
- }
- sega++;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement