Vishal Gupta
Microsoft MVP
What is this???????
Question or answer
Question or answer
What kind of help do you need....????amanwannalearn said:I wnated help in c++
particularly the for loop,and arrays(2-d)
can anyone help?
// Textual Tower Of Hanoi Solution
#include <conio.h>
#include <iostream.h>
enum POLE { LEFT, MIDDLE, RIGHT };
void transfer(int n, POLE from,POLE to, POLE temp);
const char * poles[3] = { "LEFT ",
"MIDDLE",
"RIGHT " };
const int MAX_DISK_SIZE = 30;
class Stack {
public :
Stack() {
toc = 0;
}
~Stack() {
}
unsigned short length() {
return toc;
}
int get() {
if(toc == 0)
return -1;
else
return element[toc-1];
}
void pop() {
toc --;
}
void push(int i) {
element[toc++]=i;
}
private :
int toc;
int element[MAX_DISK_SIZE];
};
Stack Pole[3];
void main(void) {
int n,i;
clrscr();
cout << "\nWelcome to the TOWER OF HANOI program by Ashish Patil"<<endl;
cout << "\nHow many disks ? ";
cin >> n;
for(i=0;i<3;i++) {
Pole[i] = Stack();
}
for(i=n-1;i>=0;i--) {
Pole[LEFT].push(i);
}
transfer(n, LEFT, RIGHT, MIDDLE);
cout <<"Process complete. Press any key to exit";
getch();
}
void transfer(int n, POLE from, POLE to, POLE temp) {
if( n > 0) {
transfer( n-1, from, temp, to);
cout << "Move disk "<< n
<< " from " << poles[from]
<< " to " << poles[to]
<<endl;
transfer( n-1, temp, to, from);
}
}
aadipa said:@The Incredible
You wanted the tower of hanoi code
amanwannalearn said:I hated that book!rubbish!
actually i picked up let us c++.
Found it worthl;ess
the_moon said:amanwannalearn said:I hated that book!rubbish!
actually i picked up let us c++.
Found it worthl;ess
Da Best Book any beginner of C++ can have is Sumita Arora.
Its very simple, yet very very informative. It covers everything from Loops to arrays to Classes to Pointers.
Highly Recommended for beginners!
WAP to Display all combinations of a 5 lettered word (No repeatations of letter)
WAP to which will check a series of Numbers given then Find out the number which doesn't belong to the series.It will then remove that number and replace it with the correct number.
anubhav_har said:Good work man.. now you can start learnign C++ and not just taking the codes and writing em down...