//works great for n<9 cant figure out why it doesnt work for n>=9//

Code:
#include <iostream>
#include <math.h>
using namespace std;

class board
{
public:

	board(int n)
	{
		this->size=n;
		list=new int[size];
		solutions=0;
		for(int i=0;i<size;i++)
			list[i]=-1;

	}
	~board()
	{
		delete list;
	}

	
	int solve(int col);
	bool process(int col,int left);
	void printboard();
private:
	int* list;
	int size;
	int solutions;
};

int board::solve(int col)
{
	
	
	if(col>=0){
		if(process(col,col-1)){
			if(col==size-1)
				solutions++;
			else
				col++;}
		else
			col--;
		return solve(col);}
	return solutions;


}
bool board::process(int col,int left)
{
	
	list[col]++;
	
	for(list[col]=list[col];list[col]<size;list[col]++){
		if(list[col]!=list[left]&&(list[col]-col)!=(list[left]-left)&&(list[col]+col)!=(list[left]+left)){
			for(left=left-1;left>=0;left--){
				if(list[col]==list[left]||(list[col]-col)==(list[left]-left)||(list[col]+col)==(list[left]+left)){
					left=col-1;
					break;}}
			if(left<0)
				break;
		}}

if(list[col]>=size){
		list[col]=-1;
		return false;}
		return true;
		
}
void board::printboard()
{
		
		int a,b,c;
		
for(a=0;a<size;a++)
{
	for(b=0;b<size;b++)
		cout<<"-----";
	cout<<endl;
	for(c=0;c<size;c++){
		cout<<"|  ";
		if(list[c]==a)
			cout<<"Q ";
		else 
			cout<<"  ";}
	
	cout<<'|'<<endl;}
for(a=0;a<size;a++)
		cout<<"-----";



}

void main()
{
	int n;
	cout<<"Enter board size: ";
	cin>>n;
	board b(n);
	cout<<b.solve(0)<<endl;
	cout<<endl;

}

Last edited by shabbir; 2Jul2008 at 21:51.. Reason: Code block