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

📄 array.cpp

📁 学习魔方编程技巧
💻 CPP
字号:
// array.cpp: implementation of the array class.
//
//////////////////////////////////////////////////////////////////////
#include "array.h"
//#define debug
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
array::array(int x)
{
	n=x;
	head=new int[n*n];
	e=false;
	for(x=0;x<n*n;x++)head[x]=0;
	init();
}
array::array(array &x)
{
	n=x.n;
	head=new int[n*n];
	for(int i=0;i<n*n;i++)
	{
		*(head+i)=x[i];
	}
	e=x.e;
}
bool array::xright()
{
	int i,j,temp;
	j=0,temp=0;
	for(i=0;i<n;i++)
	{
		temp+=head[j];
		j+=n+1;
	}
	if(temp!=(n*n+1)*n/2)return false;
	j=n-1,temp=0;
	for(i=0;i<n;i++)
	{
		temp+=head[j];
		j+=n-1;
	}
	return temp==(n*n+1)*n/2;
}
void array::show()
{
	int i,j;
	for(i=0;i<n;i++)
	{
		for(j=0;j<n;j++)
		{
			cout<<setw(4)<<head[i*n+j];
		}
		cout<<endl;
	}
}
bool array::aright()
{
	int i,j,temp,temp1;
	for(i=0;i<n;i++)
	{
		temp=temp1=0;
		for(j=0;j<n;j++)
		{
			temp+=head[i+j*n];
			temp1+=head[j+i*n];
		}
		if(temp!=temp1||temp!=(n*n+1)*n/2)return false;
	}
	return true;
}
void array::update(array&a)
{
	for(int i=0;i<n*n;i++)
	{
		*(head+i)=a[i];
	}
}
void lbiao::add(addrs *x)
{
	if(head==NULL)
	{
		head=end=x;
	}
	else
	{
		end->next=x;
		end=end->next;
	}
}
	
void lbiao::add(addrs &x)
{
	if(head==NULL)
	{
		head=end=new addrs(x);
	}
	else
	{
		end->next=new addrs(x);
		end=end->next;
	}
}
lbiao::~lbiao()
{
	while(head!=NULL)
	{
		end=head;
		head=head->next;
		delete end;
	}
}

bool operator !=(addrs &x,addrs &y)
{
	if(x.fir==y.fir)return false;
	if(x.fir==y.sec)return false;
	if(x.sec==y.fir)return false;
	if(x.sec==y.sec)return false;
	return true;
}

⌨️ 快捷键说明

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