📄 jincheng.cpp
字号:
// jincheng.cpp : Defines the entry point for the console application.
//
//#include "stdafx.h"
#include "iostream.h"
#include "stdio.h"
#include "stdlib.h"
struct datas
{
char s;
struct datas *next;
};
struct datas *ready,*excute,*block;
datas *creatnewd()
{
datas *newd;
newd=(datas *)malloc(sizeof(datas));
newd->next=NULL;
return newd;
}
datas *FindLinkNodeRear( datas *t)
{
datas *d;
d=t;
while(d->next!=NULL)
{
d=d->next;
}
return d;
}
void creatc()
{
datas *m;
m=creatnewd();
char t;
cout<<"输入进程的名字:";
cin>>t;
cout<<"stop"<<endl;
m->s=t;
cout <<m->s<<endl;
if(excute->next==NULL)
{
excute->next=m;
cout<<"creat a ready process sucess!"<<endl;
cout<<"the ready process already is runing !"<<endl;
cout<<"excute: "<<excute->next->s<<endl;
}
else
{
m->next=ready->next;
ready->next=m;
cout<<"creat a ready process sucess!"<<endl;
cout<<" ready:"<<m->s<<endl;
}
}
void creatEtoR() // intput the word t
{
if(excute->next!=NULL)
{
datas *m;
m=creatnewd();
m=ready;
while(m->next!=NULL)
m=m->next ;
m->next=excute->next;
excute->next=ready->next;
delete m;
}
else
cout<<"error: NO process exculate!"<<endl;
}
void creatEtoB() //input the word b
{
if(excute->next!=NULL)
{
excute->next->next=block->next;
block->next=excute->next;
excute->next=NULL;
cout<<"success ,a new process is runing!"<<endl;
if(ready->next!=NULL)
{
excute->next=ready->next;
ready->next=ready->next->next;
excute->next->next=NULL;
}
/* datas m;
datas n;
n=creatnewd();
n=excute
m=creatnewd();
m=block;
while(m.next!=NULL)
m=m.next;
m.next=n; */ // ? m 如何能改变原来指针得值
}
else
cout<<"error:No process is runing!"<<endl;
}
void creatBtoR() // input the word w
{
if(block->next==NULL)
cout<<"error: No block process to wake up!"<<endl;
else
{
if(excute->next==NULL)
{
excute->next=block->next;
datas *m;
m=creatnewd();
m=block->next;
block->next=m->next;
excute->next->next=NULL;
cout<<"Wake UP a process success! the process is runing!"<<endl;
}
else
{
datas *m;
m=creatnewd();
m=block->next;
block->next=m->next;
m->next=NULL;
m->next=ready->next;
ready->next=m;
cout<<"Wake UP a process success! the process is ready attitude!"<<endl;
}
}
}
void finished() // input the word e
{
if(excute->next==NULL)
cout<<"error:NO excute process is runing!"<<endl;
else
{
if(ready->next==NULL)
excute->next=NULL;
else
{
excute->next=NULL;
excute->next=ready->next;
}
}
}
void help() // input the word h
{
cout<<" this is all comment follow!"<<endl;
cout<<" h show the comment "<<endl;
cout<<" c creat a new process! "<<endl;
cout<<" t CPU time is over,exchange another process to excute!"<<endl;
cout<<" b process from excute to block and another process into excute!"<<endl;
cout<<" w wake up a process from block to ready!"<<endl;
cout<<" e finished a process and start another process from ready!"<<endl;
cout<<" s show all process spices of attitude!"<<endl;
cout<<" # quit the system!"<<endl;
}
void show(datas *t)
{
datas *m=t;
while(m->next!=NULL)
{
m=m->next;
cout<<m->s<<"\t";
}
cout<<endl;
}
void showattitude()
{
cout<<"ready process name:";
show(ready);
cout<<"block process name:";
show(block);
cout<<"excute process name:";
show(excute);
}
int main()
{
char m=' ';
ready=creatnewd();
block=creatnewd();
excute=creatnewd();
cout<<" welcome to my process system !"<<endl;
cout<<" the auther is XiaoSheng ."<<endl;
while(m!='#')
{
//cout<<" please , input your commend: "<<endl;
m=getchar();
if(m=='c')
creatc();
else if(m=='b')
creatEtoB();
else if(m=='t')
creatEtoR();
else if(m=='w')
creatBtoR();
else if(m=='e')
finished();
else if(m=='h')
help();
else if(m=='s')
showattitude();
// else
// cout<<"commend is error ,repeat input an commend!"<<endl;
}
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -