Click here to Skip to main content
15,894,106 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i wrote this source.but my prof want me to write code using stack,array and structure(position x, position y,queen's numbers).

i can't change this source to a source that my professor want to.

please help me .

it is very difficut to me ..please help!

#include <stdio.h>
#include <math.h>


#define SIZE 8

int stack[SIZE];
int count=0;


int find_place(int row);
int fill_block(int row);

int main(void)
{
    fill_block(0);

    return 0;
}



display()
{

    int row,col;
    printf("\n");
    printf("-----------",++count);
    for (row = 0; row < SIZE; row++)
    {
        for (col = 0; col< SIZE; col++)
        {
            if(stack[row]==col)printf(" Q ");
            else               printf(" _ ");
        }
        printf("\n");
    }
}


find_place(int row)
{

    for (int j = 0; j < row; j++)

    {

        if (abs(stack[row] - stack[j]) == (row - j) || (stack[j] == stack[row]) )

        {

            return 0;

        }

    }

    return 1;
}

fill_block(int row)
{

    if (row == SIZE) {

        display();

    }
    else {

        for (int i = 0; i < SIZE; i++) {

            stack[row] = i;

            if (find_place(row))

                fill_block(row+1);

  }


    }
    return -1;
}
Posted
Updated 17-Apr-10 11:19am
v3

1 solution

gsfresh wrote:
i can't change this source to a source that my professor want to.


Then you are going to fail. If we did your homework, and you avoided the chance to learn these things, how would you do the next assignment ? Why not talk to the teacher, read a book, and, if all else fails, face that you can't program and change courses ? In the first instance, you should talk to your prof, ask for references, and do your own work.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900