main.cpp:汉诺塔实现。
思路分析:
若n=1,则只需把盘子从a挪动到c
若n>1,
(1)把前n-1个盘子从a经过c挪动到b
(2)把第n个盘子从a挪动到c
(3)把前n-1个盘子从b经过a挪动回c
实现:
#include <fstream>
#include <iostream>
using namespace std;
ofstream fout("out.txt");
void Move(int n,char x,char y[......]
Category Archives: 算法&数据结构
《数据结构》栈实现进制转换
main.cpp:主程序
//Stack.h参见本分类下其它栈问题的描述
#include "../第三章 顺序栈的基本操作/Stack.h"
using namespace std;
int main()
{
int num,tmp=8;
Stack S;
InitStack(S);
cin>>num;
while(num!=0)
{
Push(S[......]
《数据结构》括号匹配问题的实现
main.cpp:主程序
//Stack.h参见本分类其它栈问题的记录。
#include "../第三章 顺序栈的基本操作/Stack.h"
using namespace std;
int main()
{
Stack S;
InitStack(S);
int tmp;
char c;
while((c=getchar())!='\n')
{
&nbs[......]
严蔚敏《数据结构》栈的基本操作
Stack.h:定义了基本操作
#include "Stack.h"
using namespace std;
void print(int e)
{
cout<<e<<" ";
}
int main()
{
int i,tmp;
Stack S;
InitStack(S);
for(i=1;i<=5;i++)
if(Push[......]
迷宫问题,C++的栈实现
Stack.h:定义了栈的基础操作和数据类型
#include <iostream>
const int Stack_Size=9;
const int Stack_Incricement=2;
enum {OK=0,WRONG=-1};
typedef int Status;
typedef struct
{
int x;
int y;
}Pos;
typedef struct
{
Pos CurPos;
int[......]