简体   繁体   English

使用SJF(SPN)算法推送队列

[英]pushing queue using SJF (SPN) Algorithm

I have a queue and I want to push into this one using the SJF algorithm also called SPN (shortest process next) I use a function to estimate the "job". 我有一个队列,我想使用也称为SPNSJF算法 (接下来是最短的过程)来推入这个队列,我使用一个函数来估算“工作”。 The elements I want to push are structs, I get the "job" using the parameters of that struct. 我要推送的元素是结构体,我使用该结构体的参数获得了“工作”。 For example: 例如:

typedef struct {
 int* a;
 int* b;
}element;

getJob(element*){
int job = element->a * element->b;
return job;
}

It doesn't matter how is defined that function, I want to know how to implement SJF or SPN algorithm using it. 对该函数的定义无关紧要,我想知道如何使用它来实现SJF或SPN 算法

I think that a priority queue is what you're looking for. 我认为您正在寻找优先级队列。 Here there are several implementation, also for c and with a little of modifications you can use for your purpose. 这里有几种实现方式,也适用于c语言,并做了一些修改即可用于您的目的。

This data structure allow only two operation 这个数据结构只允许两个操作

  1. insert an element 插入一个元素
  2. extract that one with highest priority 提取优先级最高的那个

In your case the priority is higher, the lower the job. 在您的情况下,优先级越高,工作越低。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM