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

📄 shiyan9.3.cpp

📁 模仿港台《百万富翁》节目
💻 CPP
字号:

#include<iostream.h>
#include<iomanip.h>
struct person
{
	char name[10];
	int id;
	float mark;
	person *next;
};
person *head;
person *creat()
{
    int i=1;
	person *s,*p;
	s=new person;
	cout<<"input the id : ";
	cin>>s->id;
	cout<<"input the name:";
	cin>>s->name;
	cout<<"input the mark:";
	cin>>s->mark;
	head=NULL;
	while(s->id!=0)
	{
	  if(head==NULL)head=s;
		else
			p->next=s;
		p=s;
	  s=new person;
	  cout<<"input the id : ";
	  cin>>s->id;if(s->id==0)continue;
	  cout<<"input the name:";
	  cin>>s->name;i++;
	  cout<<"input the mark:";
	  cin>>s->mark;
	}
	p->next=NULL;
	delete s;
	return(head);
	
}
void showlist(const person*head)
{
	cout<<"ID"<<setw(10)<<"name"<<setw(10)<<"mark"<<endl;
	while(head)
	{
		cout<<head->id<<setw(10)<<head->name<<setw(10)<<head->mark<<endl;
		head=head->next;
	}
}

person *insert()
{
	person *s,*p,*q;int a;
	s=new person;
	cin>>a;
	cout<<"input the id : ";
	cin>>s->id;
	cout<<"input the name:";
	cin>>s->name;
	cout<<"input the mark:";
	cin>>s->mark;
	if(head->id == a )
	{
		s->next =head;
	    head=s;
	
		return(head);
	}
	for(q=head,p=head->next ;p;q=p,p=p->next )
		if(p->id == a )
		{
			s->next =p;
		    q->next =s;
		    return(head);
		}
		if(q->id !=a )
		{
			q->next=s;
			return(head);
		}
		return(head);
}
person *del()
{
	person *p;
	int k;
	cout<<"input the ID you want to delete"<<endl;
	cin>>k;
	if(head->id ==k)
	{
		p=head;
		head=head->next ;
		delete p;
		cout<<" it is ok   "<<endl;
		return(head);
	}
	for(person *pg=head;pg->next ;pg=pg->next )
	{
		if(pg->next ->id==k)
		{
			p=pg->next ;
			pg->next =p->next ;
			delete p;
			cout<<"it is ok   "<<endl;
			return(head);
		}
	}
		cout<<"there is no exstent"<<endl;
		return(head);
}
void main()
{
	person *pp=creat();
	cout<<"*************************************************************"<<endl;
	showlist(pp);
	cout<<"intput the num's front you want to insert"<<endl;
	pp=insert();
	cout<<"*************************************************************"<<endl;
	showlist(pp);
	del();
	pp=del();
	cout<<"*************************************************************"<<endl;
	showlist(pp);
}

⌨️ 快捷键说明

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