summaryrefslogtreecommitdiffstats
path: root/2022-2/L6/mitsuo/BibliotecaPilaGenerica.cpp
diff options
context:
space:
mode:
authorMitsuo Tokumori <[email protected]>2023-08-18 01:56:52 -0500
committerMitsuo Tokumori <[email protected]>2023-08-18 01:56:52 -0500
commit49d4392ca1972c8d66b1015f2cdda414d94812b8 (patch)
tree13585bcb546d97b96ec669457c06fc27f2d66ab7 /2022-2/L6/mitsuo/BibliotecaPilaGenerica.cpp
parentd6e56dbe184cac37d7aa5cebe3e1db108dee4a28 (diff)
downloadLP1-49d4392ca1972c8d66b1015f2cdda414d94812b8.tar.gz
LP1-49d4392ca1972c8d66b1015f2cdda414d94812b8.tar.bz2
LP1-49d4392ca1972c8d66b1015f2cdda414d94812b8.zip
Fix naming. Add leading 0 to lab names
Diffstat (limited to '2022-2/L6/mitsuo/BibliotecaPilaGenerica.cpp')
-rw-r--r--2022-2/L6/mitsuo/BibliotecaPilaGenerica.cpp99
1 files changed, 0 insertions, 99 deletions
diff --git a/2022-2/L6/mitsuo/BibliotecaPilaGenerica.cpp b/2022-2/L6/mitsuo/BibliotecaPilaGenerica.cpp
deleted file mode 100644
index 01a7dc3..0000000
--- a/2022-2/L6/mitsuo/BibliotecaPilaGenerica.cpp
+++ /dev/null
@@ -1,99 +0,0 @@
-#include <iostream>
-#include <fstream>
-#include "BibliotecaPilaGenerica.h"
-
-using namespace std;
-
-/* NEXT: (void *), DATA: (int *) */
-enum nodeIndices { NEXT, DATA };
-
-void cargapila(void *&pila, void *arreglo)
-{
- int i;
- int **numbers = (int **) arreglo;
- pila = nullptr;
- for (i = 0; numbers[i]; i++) {
- push(pila, numbers[i]);
- }
-}
-
-void push(void *&pila, void *data)
-{
- void **node = new void * [2];
- node[NEXT] = pila;
- node[DATA] = data;
- pila = node;
-}
-
-void *pop(void *&pila)
-{
- void **node;
- if (pila == nullptr) {
- return nullptr;
- } else {
- node = (void **) pila;
- pila = node[NEXT];
- return node[DATA];
- }
-}
-
-int pilavacia(void *pila)
-{
- return pila == nullptr;
-}
-
-void imprimepila(
- void *pila,
- void (*imprimenumero)(ostream &out, void *),
- const char *filename
-) {
- ofstream out(filename);
- if (!out) {
- cerr << "Error: no se pudo abrir archivo\n";
- }
- void **next;
- void **node;
- int data;
-
- next = (void **) pila;
- while (next) {
- node = (void **) next;
- imprimenumero(out, node[DATA]);
-
- next = (void **) node[NEXT];
- }
-}
-
-/* hanoi */
-void muevepila(void *pilasrc, void *&piladest)
-{
- void *pilaaux = nullptr;
-
- /* count elements */
- int i = 0;
- void **next = (void **) pilasrc;
- while (next) {
- next = (void **) *next;
- i++;
- }
- // cout << "n = " << i << '\n';
- hanoi(i, pilasrc, nullptr, piladest);
-}
-
-static void hanoi(int n, void *pila1, void *pila2, void *pila3)
-{
- /* FIXME: I don't know where it's the bug. Here or in pop(). Also the stack
- * representation different from what is asked in the problem statement */
- void *data;
- if (n == 0) {
- return;
- } else if (n == 1) {
- data = pop(pila1);
- push(pila3, data);
- } else {
- hanoi(n - 1, pila1, pila3, pila2);
- data = pop(pila1);
- push(pila3, data);
- hanoi(n - 1, pila2, pila1, pila3);
- }
-}