Skip to content

Commit 272cd35

Browse files
authored
Merge pull request kelvins#98 from DantasB/hanoi_c
Adicionando a resolução da torre de hanoi em C
2 parents a55cc6a + 8eb586c commit 272cd35

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ Com o objetivo de alcançar uma abrangência maior e encorajar novas pessoas a c
2727
| [Mín. e Máx. Recursivo][28] | [C/C++](./src/c/MaxMinRecursivo.c) | Java | [Python](./src/python/maximo_minimo_recursivo.py) | [Go](./src/go/maximominimo/MaximoMinimo.go) | Ruby | [JS](./src/javascript/RecursiveMinAndMax.js) | Pascal | Swift | [Rust](./src/rust/min_max_recursivo.rs) |
2828
| Mín. e Máx. D&C | C/C++ | Java | [Python](./src/python/maximo_recursivo_dc.py) | [Go](./src/go/maximominimo/MaximoMinimo.go) | Ruby | JS | Pascal | Swift | Rust |
2929
| [Passeio do Cavalo][30] | C/C++ | Java | [Python](./src/python/passeio_do_cavalo.py) | Go | Ruby | JS | Pascal | Swift | Rust |
30-
| [Torre de Hanói][33] | C/C++ | [Java](./src/java/TorreDeHanoi.java) | [Python](./src/python/torre_de_hanoi.py) | [Go](./src/go/hanoi/hanoi.go) | [Ruby](./src/ruby/Hanoi.rb) | [JS](./src/javascript/TorreDeHanoi.js) | Pascal | [Swift](./src/swift/hanoi.swift) | [Rust](./src/rust/torre_hanoi.rs) |
30+
| [Torre de Hanói][33] | [C/C++](./src/c/TorreDeHanoi.c) | [Java](./src/java/TorreDeHanoi.java) | [Python](./src/python/torre_de_hanoi.py) | [Go](./src/go/hanoi/hanoi.go) | [Ruby](./src/ruby/Hanoi.rb) | [JS](./src/javascript/TorreDeHanoi.js) | Pascal | [Swift](./src/swift/hanoi.swift) | [Rust](./src/rust/torre_hanoi.rs) |
3131
| [Algoritmo Genético][51] | C/C++ | Java | [Python](./src/python/genetic_algorithm.py) | Go | Ruby | JS | Pascal | Swift | Rust |
3232

3333
| Estruturas de Dados | C/C++ | Java | Python | Go | Ruby | JS | Pascal | Swift | Rust |

src/c/TorreDeHanoi.c

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
Torre de Hanoi em C
3+
Bruno Dantas de Paiva - 2021
4+
https://github.com/DantasB
5+
*/
6+
7+
#include <stdio.h>
8+
9+
void hanoi(int pino0, int pino2, int pino1, int discos)
10+
{
11+
if (discos == 1)
12+
printf("Move de %i para %i\n", pino0, pino2);
13+
14+
else
15+
{
16+
hanoi(pino0, pino1, pino2, discos - 1);
17+
hanoi(pino0, pino2, pino1, 1);
18+
hanoi(pino1, pino2, pino0, discos - 1);
19+
}
20+
}
21+
22+
int main()
23+
{
24+
hanoi(0, 2, 1, 3);
25+
return 0;
26+
}

0 commit comments

Comments
 (0)