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

📄 migonghuishuo.cpp

📁 关于数据结构的各章节的c原代码实现
💻 CPP
字号:
// migonghuishuo.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <stdio.h>
struct stack_node
{
	int x;
	int y;
	struct stack_node* next;
	
};
typedef struct stack_node node;
typedef node* link;
link path=NULL;
link push(link stack,int x,int y)
{ 
	link newnode;
	newnode=(link)malloc(sizeof(node));
	if (!newnode)
	{
		printf("内存分配失败\n");
		return NULL;
	}
    newnode->x=x;
    newnode->y=y;
	newnode->next=stack;
	stack=newnode;
	return stack;
}
link pop(link stack,int *x,int *y)
{
	link temp;
	if(stack!=NULL)
	{
	temp=stack;
	*x=temp->x;
	*y=temp->y;
	stack=stack->next;
	free(temp);
	return stack;
	}
	else
		*x=-1;
}

int main(int argc, char* argv[])
{  
    int maze[7][10]={
		1,1,1,1,1,1,1,1,1,1,
		1,0,1,0,1,0,0,0,0,1,
		1,0,1,0,1,0,1,1,0,1,
		1,0,1,0,1,1,1,0,0,1,
		1,0,1,0,0,0,0,0,1,1,
		1,0,0,0,1,1,1,0,0,1,
		1,1,1,1,1,1,1,1,1,1
	};
	int x=5;
	int y=8;
	while (x!=1||y!=1)
	{
		maze[x][y]=2;
		if (maze[x-1][y]<=0)
		{
			x=x-1;
			path=push(path,x,y);
		}
		else
			if (maze[x+1][y<=0])
			{
				x=x+1;
				path=push(path,x,y);
			}
			else 
				if (maze[x][y-1]<=0)
				{
					y=y-1;
					path=push(path,x,y);
				}
                else
					if (maze[x][y+1]<=0)
					{
						y=y+1;
						path=push(path,x,y);
					}
                 else
				 {
					 maze[x][y]=3;
				 path=pop(path,&x,&y);
				 }

	}         
maze[x][y]=2;
for (int i=0;i<7;i++)
{
	for (int j=0;j<10;j++)
	{
		printf("%d\n",maze[i][j]);
	}
}
	return 0;
}

⌨️ 快捷键说明

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