一个关于打印单链表的错误
来源:互联网 发布:中英文分词 python 编辑:程序博客网 时间:2024/05/07 01:48
#include<stdlib.h>
#include<stdio.h>
struct process
{
int name;//进程名称
int priority;//进程优先级
int time;//进程运行时间
char state;//进程状态,用R表示就绪,用E表示结束
struct process *next;
};
//进程初始化
void initialize(struct process *head);
//运行进程
int run(struct process *head);
int main()
{
int a=1;//a表示程序的运行次数
struct process *head;
head=(struct process *)malloc(sizeof(struct process ));
head->next=NULL;
initialize(head);
while(head->next)
{
printf("第%d次运行",a);
run(head);
a++;
}
system("PAUSE");
return 0;
}
//进程初始化
void initialize(struct process *head)
{
int i;
struct process *s,*p; //s为插入的新节点,p为标记节点
for(i=0;i<5;i++)
{
s=(struct process *)malloc(sizeof(struct process));
p=head;
printf("请输入第%d个进程的优先级,运行时间,用空格隔开\n",i+1);
scanf("%d %d",&s->priority,&s->time);
fflush(stdin);
s->state='R';
s->name=i+1;
while(p->next)
{
if(s->priority>p->next->priority)
break;
p=p->next;
}
s->next=p->next;
p->next=s;
}
}
//运行进程
int run(struct process *head)
{
struct process *current,*p;//current为正在运行的进程的节点,p为标记节点
p=head;
current=p->next;
p->next=current->next;
printf("\n开始运行进程%d\n",current->name);
current->time=current->time-1;
current->priority=current->priority-1;
if(current->time>0)
{
printf("进程%d运行完之后为就绪状态\n",current->name);
while(p->next)
{
if(current->priority>=p->next->priority)
break;
p=p->next;
}
current->next=p->next;
p->next=current;
}
else
{
printf("进程%d运行完之后为完成状态\n",current->name);
delete current;
}
printf("运行完毕之后的就绪进程队列为:\n");
while(head->next)
{
printf("%d",head->next->name);
head=head->next;
}
/*WRONG:
while(p->next)
{
printf("%d",p->next->name);
p=p->next;
}
*/
printf("\n\n\n");
return 0;
}
#include<stdio.h>
struct process
{
int name;//进程名称
int priority;//进程优先级
int time;//进程运行时间
char state;//进程状态,用R表示就绪,用E表示结束
struct process *next;
};
//进程初始化
void initialize(struct process *head);
//运行进程
int run(struct process *head);
int main()
{
int a=1;//a表示程序的运行次数
struct process *head;
head=(struct process *)malloc(sizeof(struct process ));
head->next=NULL;
initialize(head);
while(head->next)
{
printf("第%d次运行",a);
run(head);
a++;
}
system("PAUSE");
return 0;
}
//进程初始化
void initialize(struct process *head)
{
int i;
struct process *s,*p; //s为插入的新节点,p为标记节点
for(i=0;i<5;i++)
{
s=(struct process *)malloc(sizeof(struct process));
p=head;
printf("请输入第%d个进程的优先级,运行时间,用空格隔开\n",i+1);
scanf("%d %d",&s->priority,&s->time);
fflush(stdin);
s->state='R';
s->name=i+1;
while(p->next)
{
if(s->priority>p->next->priority)
break;
p=p->next;
}
s->next=p->next;
p->next=s;
}
}
//运行进程
int run(struct process *head)
{
struct process *current,*p;//current为正在运行的进程的节点,p为标记节点
p=head;
current=p->next;
p->next=current->next;
printf("\n开始运行进程%d\n",current->name);
current->time=current->time-1;
current->priority=current->priority-1;
if(current->time>0)
{
printf("进程%d运行完之后为就绪状态\n",current->name);
while(p->next)
{
if(current->priority>=p->next->priority)
break;
p=p->next;
}
current->next=p->next;
p->next=current;
}
else
{
printf("进程%d运行完之后为完成状态\n",current->name);
delete current;
}
printf("运行完毕之后的就绪进程队列为:\n");
while(head->next)
{
printf("%d",head->next->name);
head=head->next;
}
/*WRONG:
while(p->next)
{
printf("%d",p->next->name);
p=p->next;
}
*/
printf("\n\n\n");
return 0;
}
0 0
- 一个关于打印单链表的错误
- 一个关于打印预览的问题
- 关于打印图片的一个例子
- 关于打印浮点数的一个问题
- 关于直接打印一个对象的引用
- 一个关于环境的错误:
- 关于sql2012的一个错误
- 一个关于file_put_contents的错误
- 关于打印一个有趣的数字图形的问题
- 一个关于VB工程引用的错误!
- display 标签,关于排序的一个错误
- 一个关于jar包的低级错误
- 关于Tomcat启动的一个错误
- 关于dll调用的一个常见错误
- 关于Hudson上配置的一个错误
- 关于AT91一个GPIO的错误
- 关于一个写Masm的小错误........
- 关于释放指针引发的一个错误
- Hello world
- metasploit 学习
- vim教程总结
- ubuntu14.04中安装opencv2.4.9
- JavaScript学习入门
- 一个关于打印单链表的错误
- iOS 9 中出现的问题
- 弹出层(封装代码)
- Neper软件介绍及安装视频教程
- 恭喜Leovige成为IT人
- 九宫格解锁可用修改版
- 黑马程序员——C语言中进制转换的要素和运算符笔记+习题
- Linux系统与Windows的基本区别
- Jquery选择器