Created
April 7, 2017 07:44
-
-
Save RicardoLara/fabaa4d5845e5757b58e694841ebdeac to your computer and use it in GitHub Desktop.
Práctica 3 5/5[AA] - Daniel Cruz García
This file contains hidden or 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 <stdio.h> | |
#include "tiempo.h" | |
long long int TorresHanoi(int n, int ini, int med, int fin){ | |
static long long int movs = 0; | |
if(n == 1) movs++; //printf("Movimiento: %d -> %d\n",ini,fin); | |
else { | |
TorresHanoi(n-1, ini, fin, med); | |
//printf("Movimiento: %d -> %d\n",ini,fin); | |
movs++; | |
TorresHanoi(n-1, med, ini, fin); | |
} | |
return movs; | |
} | |
int main(){ | |
int j,n; | |
double utime0, stime0, wtime0,utime1, stime1, wtime1; | |
for(j=0; j<50; j++){ | |
printf("\n------------------- NUMERO %d --------------------- \n",j+1); | |
printf("Numero de discos: %d\n",j+1); | |
uswtime(&utime0, &stime0, &wtime0); | |
printf("Se realizaron %lld movimientos\n",TorresHanoi(j+1,1,2,3)); | |
uswtime(&utime1, &stime1, &wtime1); | |
printf("real (Tiempo total) %.10f s\n", wtime1 - wtime0); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment