⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cccccccccccccccccccccccccccc.cpp

📁 一个模拟进程管理的程序
💻 CPP
字号:
#include<iostream.h>
class List;
class ListNode
{
	friend class List;
public:
	ListNode(int d=NULL,ListNode *l=NULL);
	int getdata(){return data;}
	ListNode * getlink(){return link;}
private:
	int data;
	ListNode *link;
};
class List
{
public:
	int Insert(char x, int i);
    void Remove(int i);
	List();
	~List();
	ListNode *getfirst(){return first;}
	ListNode *getlast(){return last;}
	char get(int i);
	void printf();
private:
	ListNode * first,* last;
};

ListNode::ListNode(int d,ListNode *l)
{
	data=d;
	link=l;
}
List::List()
{int d=NULL;
	first=last=new ListNode(d);
	
}

int List::Insert(char x, int i)
{
	ListNode *p=first;int k=0;
	while(p!=NULL&&k<i-1)
	{
		p=p->link;
		k++;
	}
	if(p==NULL&&first!=NULL)
	{
	  cout<<"Invaid position for Iosertation! \n";
	  return 0;
	}
	ListNode *newnode=new ListNode(x,NULL);
	if(first==NULL||i==0)
	{
		newnode->link=first;
		if(first==NULL)
			last=newnode;
		first=newnode;
	}
	else
	{
		newnode->link=p->link;
		if(p->link==NULL)
			last=newnode;
		p->link=newnode;
	}
	return 1;
}
void List::Remove(int i)
{
	ListNode *p=first,* q;int k=0;
	
	while(p!=NULL&&k<i-1)
	{
        p=p->link;
		k++;
	}
	if(p==NULL||p->link==NULL)
	{
		cout<<"Invalid position for Deletion!\n";
		
	}
	if(i==0)
	{
		q=first;
		p=first=first->link;
	}
	else
	{
		q=p->link;
		p->link=q->link;
	}
	if(q==last)
		last=p;
	k=q->data;
	delete q;
}
List::~List()
{
	ListNode *p;
	while(first!=NULL)
	{
		p=first;first=first->link;delete p;
	}
}
char List::get(int i)
{
	ListNode *q=first;int h;
	for(int j=0;j<i;j++)
	{
		if(q->link==NULL)
		{	cout<<"Invalid position for Deletion!\n"<<endl;
			return 0;
		}
		q=q->link;
	}
	h=q->data;
	return h;
}
void List::printf()
{
  ListNode *p=first;char k;
  while(p!=NULL){k=p->data;p=p->link;cout<<k<<" ";}
}
void main()
{
 List donow;
 List buffer;
 List waste;
 if(buffer.get(0)!=NULL){char n=buffer.get(0);waste.Insert(n,0);buffer.Remove(0);}
 else{char q;cin>>q;donow.Insert(q,0);cout<<"donow is"<<q<<endl;
      buffer.Insert(q,0);donow.Remove(0);cout<<"buffer is"<<q<<endl;
 waste.Insert(q,0);buffer.Remove(0);cout<<"waste is"<<q<<endl;}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -