// veze.cpp 
 
#include "stdafx.h"
#include <iostream>
#include <string>
#include <cassert>
 
using namespace std;
 
const int N = 5;
 
struct Vez {
  int k;
  int p[N];
};
 
Vez A, B, C;
 
void init (Vez & X){
    X.k=0;
    for (int i=0; i<N; i++)
        X.p[i]=0;
}
 
void setup (Vez& X){
    X.k=N;
    for (int i=0; i<N; i++)
        X.p[i]=N-i;
}
 
void vypis(Vez &X){
	for (int i=0; i<X.k; i++)
		cout<< X.p[i]<< " ";
	for (int i=X.k; i<N; i++)
		cout<<" "<< " ";
}
 
void prehod ( Vez & X, Vez & Z){
    assert (X.k > 0);
    int v = X.p[X.k-1];
    X.p[X.k-1] = 0;
    X.k--;
 
    assert (Z.k < N);
    if (Z.k > 0)
        assert (Z.p[Z.k-1] > v);
    Z.p[Z.k]= v;
    Z.k++;
 
	// Z.p[Z.k ++] = X.p[X.k-- -1]
	vypis(A);
	cout<<" | ";
	vypis(B);
	cout<<" | ";
	vypis(C);
	cout <<endl;
}
 
void presun(Vez &X, Vez &Y, Vez &Z, int pocet)
{
	if (pocet > 1) presun(X, Z, Y, pocet-1);
	prehod(X, Z);
	if (pocet > 1) presun(Y, X, Z, pocet-1);
}
 
int _tmain(int argc, _TCHAR* argv[])
{
    init(B);
    init(C);
    setup(A);
 
	vypis(A);
	cout<<" | ";
	vypis(B);
	cout<<" | ";
	vypis(C);
 
	cout <<endl;
 
	presun(A,B,C,N);
 
    cout << "End" << endl;
    system ("pause");
    return 0;
}
 
veze_ctvrtek.txt · Last modified: 2017/03/23 14:18 by 147.32.8.110
 
Recent changes RSS feed Creative Commons License Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki