Created
September 15, 2014 12:09
-
-
Save HackToHell/82ad69d9bb58c9461b43 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "stdafx.h" | |
#include<string> | |
#include<iostream> | |
#include<conio.h> | |
#define SIZE 20 | |
using namespace std; | |
class stack{ | |
public: | |
int a[SIZE]; | |
int top; | |
stack(){ | |
top=-1; | |
} | |
void push(int e){ | |
if(top!=SIZE){ | |
a[++top]=e; | |
} | |
else{ | |
cout<<"\nFull"; | |
} | |
} | |
int pop(){ | |
int e; | |
if(top!=(-1)){ | |
e = a[top]; | |
a[top]=0; | |
top--; | |
return e; | |
} | |
else{ | |
cout<<"\nEmpty"; | |
return NULL; | |
} | |
} | |
}; | |
static stack a[3]; | |
void changetowers(int s,int x,int y,int z){ | |
if(s>0){ | |
changetowers(s-1,x,z,y ); | |
int d=a[x].pop(); | |
a[y].push(d); | |
cout<<"\nDisnk Number"<<d<<" Disk from tower" <<x<<" to the tower"<<y; | |
changetowers(s-1,z,y,x); | |
} | |
} | |
void hanoiit(int n){ | |
//three towers | |
for(int i=n;i>0;i--) | |
a[0].push(i); | |
changetowers(n,0,1,2); | |
} | |
void main(){ | |
int n; | |
cout<<"Enter the size of the twoer"; | |
cin>>n; | |
hanoiit(n); | |
cin.get(); | |
std::cout.flush(); | |
std::cin.ignore(10000, '\n'); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment