资源简介
进程调度时间片轮转+优先级进程调度(操作系统课程设计),用队列数据结构,C++实现。

代码片段和文件信息
#include
#include
#include
using namespace std;
struct PCBNode
{
string name;
float priority; //优先级
float runTime; //总的需要运行时间
float remainTime; //剩下需要运行时间
float arriveTime; //进入就绪队列时间
float startTime; //开始运行时间
float finishTime; //结束运行时间
float totalTime; //周转时间
float weightTotalTime; //带权周转时间
PCBNode * next;
};
struct linkQueue //队列定义
{
PCBNode * front; //队头指针
PCBNode * rear; //队尾指针
};
//队列初始化
void InitialQueue(linkQueue& q);
//输入PCBNode
void Input(PCBNode& p);
//队列构造
void CreateQueue(linkQueue& q int n);
//按时间排序
void SortByTime(linkQueue& q int n);
//时间片轮转算法
void RoundRobin(linkQueue& q int n);
//按优先级排序
void SortByPri(linkQueue& q int n);
//优先级算法
void Priority(linkQueue& q int n);
//打印队列
void PrintQueue(linkQueue& q);
int main()
{
int i = 1;
while (i)
{
char sign;
cout << “算法选择:时间片轮转/T,优先级/P“ < cin >> sign;
if (sign == ‘t‘ || sign == ‘T‘)
{
linkQueue queue;
InitialQueue(queue);
int num = 0;
cout << “输入进程个数“ << endl;
cin >>num;
CreateQueue(queue num);
SortByTime(queue num);
RoundRobin(queue num);
PrintQueue(queue);
}
else if (sign == ‘p‘ || sign == ‘P‘)
{
linkQueue queue;
InitialQueue(queue);
int num = 0;
cout << “输入进程个数“ << endl;
cin >>num;
CreateQueue(queue num);
SortByPri(queue num);
Priority(queue num);
PrintQueue(queue);
}
cout << endl;
cout << “继续请输入1退出请输入0“ < cin >>i;
}
return 0;
}
void InitialQueue(linkQueue& q)
{
q.front = NULL;
q.rear = NULL;
}
void Input(PCBNode& p)
{
//需要用户输入的信息
cout << “输入进程名称“ < cin >> p.name;
cout << “输入到达时间“ << endl;
cin >> p.arriveTime;
cout << “输入运行时间“ << endl;
cin >> p.runTime;
cout << “输入优先级“ << endl;
cin >> p.priority;
//自动初始化的信息
p.startTime = 0; //开始时间
p.finishTime = 0; //完成时间
p.remainTime = p.runTime; //还需要时间
p.totalTime = 0; //周转时间
p.weightTotalTime = 0; //带权周转时间
p.next = NULL;
}
void CreateQueue(linkQueue& q int n)
{
for (int i=0; i {
PCBNode pcb;
Input(pcb);
if (q.front == NULL)
{
PCBNode * temp = new PCBNode;
* temp = pcb;
q.front = q.rear = temp;
q.rear->next = NULL;
}
else
{
//此处必须新建一个PCBNode,否则连不上队列
PCBNode * temp = new PCBNode;
* temp = pcb;
q.rear->next = temp;
q.rear = q.rear->next;
q.rear->next = NULL;
}
}
}
void SortByTime(linkQueue& q int n)
{
//冒泡排序
for (int i=0; i {
PCBNode * before = q.front;
PCBNode * current = before->next;
PCBNode * after = current->next;
while (current != NULL)
{
//对开头三个节点的比较,因为后续节点使用current和after比较
//三个指针向后移一位之后,第二和第三的比较被忽略了,所以将其加在这里。
if (before == q.front)
{
//比较前两个节点
if (before->arriveTime > current->arriveTime)
{
q.front = current;
before->next = curr
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 10251 2010-01-25 16:00 操作系统(时间片轮转+优先级进程调度)\main.cpp
目录 0 2010-05-08 23:38 操作系统(时间片轮转+优先级进程调度)
----------- --------- ---------- ----- ----
10251 2
- 上一篇:数据压缩LZW算法源代码
- 下一篇:funcode太空战机
相关资源
- 移木块游戏,可以自编自玩,vc6.0编写
- C++纯文字DOS超小RPG游戏
- 安科瑞智能电能表MODBUS通讯程序 VC6
- 九齐单片机源码
- Qt画图工具源码(qgraphics draw)
- qt 串口助手源码
- modbus 主机源码
- 《LINUX C编程从初学到精通》光盘源码
- OLED驱动源码
- tm1650+stm32f103源码(board_tm1650.c)
- cheat engine 7.2源码
- CrySearch内存搜索器源码
- FTP客户端源码(c++)
- MFC视频播放器源码(支持avi/wma/mp3等格
- CreatBitmap图片合成源码
- vs2008 can总线通讯源码
- 宠物管理系统课程设计(源码+数据库
- Windows扩展命令程序(源码)
- c语言实现火车订票系统(控制台)源
- 鼠标连点器(附源码)
- c++ 简易贪吃蛇源码
- 杀毒软件源码
- 经典外汇智能交易程序Amazing3.1源码(
- 微型文件系统源码(FatFs)
- 海康私有流分析接口源码(附使用说
- VC6 USB开发源码
- SVM算法实现(源码+文档)
- 俄罗斯方块游戏源码(Tetris)
- 步进电机控制(源码+文档)
- c++ 定时关机程序源码
评论
共有 条评论