c1.cpp

来自「实现集合的交和并集」· C++ 代码 · 共 50 行

CPP
50
字号
#include<iostream.h>
#include"c1.h"
template<class Type>void CircList<Type>::Insert(const Type& value)
{
	Type x;
	cout<<"Enter the password:"<<endl;
	cin>>x;
	if(current==NULL)
		current=first=new CircListNode<Type>(value, x, first);
	else
	{
		CircListNode<Type>*temp=current; 
		current=new CircListNode<Type>(value,x,current->link);
		temp->link=current;
		current=current->link;
	}
}
template<class Type>void CircList<Type>::Remove()
{
	if(current!=NULL)
	{
		CircListNode<Type>* temp=current;
		current=current->link;
		delete temp;
		if(current==first)
			if(first->link==first)
				current=NULL;
			else current=current->link;
	}
}
template<class Type>void CircList<Type>::Josephus(int n,int m)
{
	Firster();
	for(int i=0;i<n-1;i++)
	{
		for(int j=0;j<m-1;j++) Next();
		cout<<"Delete person"<<GetData1()<<endl;
		m=GetData2();
		Remove();
	}
}
void main()
{
	CircList<int> c;
	int n,m;
	cout<<"Enter the Number of Contestants:"<<endl;
	cin>>n>>m;
	for(int i=1;i<=n;i++) c.Insert(i);
		c.Josephus(n,m);
}

⌨️ 快捷键说明

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