| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 613 人关注过本帖
标题:皇后问题,怎么用栈实现
只看楼主 加入收藏
tiantian0623
Rank: 1
等 级:新手上路
帖 子:14
专家分:0
注 册:2008-4-23
收藏
 问题点数:0 回复次数:0 
皇后问题,怎么用栈实现
这个程序有什么问题,高手帮忙改一下啊
#include<stdio.h>
#include<stdlib.h>
#define max 20
 struct{
    int line;//行
    int flag;//标志,为1时位置合理
}st[max];
 int top=0;
void queue(int n)
{
    int i;top++;
st[top-1].line=1;st[top-1].flag=1;

while(top>0&&top<n)
{

    while(st[top-1].line<n)
{
    for(i=0;i<top-1;i++)
if(st[i].line==st[top-1].line||(abs(top-1-i)==abs(st[top-1].line-st[i].line)))
{st[top-1].flag=0;break;}
else
st[top-1].flag=1;
if(st[top-1].flag==1)break;
else if(st[top-1].flag==0)st[top-1].line++;
    }
if(st[top-1].flag==1)
{top++;st[top-1].line=1;}
else if (st[top-1].flag==0)
top--;
}


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

printf("\t(%d,%d)",st[j].line,j);
}

void main()
{
    int m;
    scanf("%d",&m);
    printf("%d皇后问题",m);
        queue(m);
}
搜索更多相关主题的帖子: 皇后 
2008-04-27 21:52
快速回复:皇后问题,怎么用栈实现
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.011599 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved