gzc4188
gzc4188
关注数: 19
粉丝数: 1
发帖数: 12
关注贴吧数: 0
UNLV附近分租 本人有2间空房想分租给UNLV的在校学生,详细信息请联系微信zitung1019
有问题求教,我写的差不多了,可以cl, 但是出现的都是0 怎么办! #include <iostream> #include <iomanip> using namespace std; int n; int movecount; const int STACKSIZE = 20; int stack1[STACKSIZE]; int stack2[STACKSIZE]; int stack3[STACKSIZE]; int size1 = 0, size2 = 0, size3 = 0; //17 void push(int which, int value) { if(which == 1) stack1[size1++] = value; else if( which == 2) stack2[size2++] = value; else(which == 3); stack3[size3++] = value; } //26 int pop(int which) { if(which==1) return stack1[--size1]; else if(which==2) return stack2[--size2]; else(which==3); return stack3[--size3]; } void initstacks(int which) { memset(stack1, size1 = 0, sizeof(stack1)); memset(stack2, size2 = 0, sizeof(stack2)); memset(stack3, size3 = 0, sizeof(stack3)); } void printstack(int which) { if(which == 1) for(int i=0; i<size1; i++) cout << stack1[i]<< endl; else if(which == 2) for(int i=0; i<size2; i++) cout << stack2[i]<< endl; else(which == 3); for(int i=0; i<size3; i++) cout << stack3[i]<< endl; } void printstacks(int which) { printstack(1); printstack(2); printstack(3); } void move(int from, int to) { int i=pop(from); push(to,i); } void solve(int n ,int a, int b, int c) { if (n==1) move(a,b); else { solve(n-1,a,c,b); solve(1,a,b,c); solve(n-1,c,b,a); } } int main(void){ cout << "Enter n: "; cin >> n; initstacks(0); printstacks(0); solve(n,1,2,3); printstacks(0); return 0; }
HELP!!!! Towers of Hanoi!!!! #include <iostream> #include <iomanip> using namespace std; int n; int movecount; const int STACKSIZE = 20; int stack1[STACKSIZE]; int stack2[STACKSIZE]; int stack3[STACKSIZE]; int size1 = 0, size2 = 0, size3 = 0; void push(int which, int value) { } int pop(int which) { } void initstacks() { } void printstack(int which) { } void printstacks() { } void move(int from, int to) { } void solve(int n ,int a, int b, int c) { if (n==1) move(a,b); else { solve(n-1,a,c,b); solve(1,a,b,c); solve(n-1,c,b,a); } } int main(void){ cout << "Enter n: "; cin >> n; initstacks(); printstacks(); solve(n,1,2,3); return 0; }
我 郭紫臣 有认识的吗?
1
下一页