Fandom

Scratchpad

PLE:Unidad5Ejercicio11

219,351pages on
this wiki
Add New Page
Discuss this page0 Share
/*
programa:       ejH511
fecha:          25/04/07
Descipcion:     Lee un crucigrama almacenado en un fichero.
*/

#include<iostream.h>
#include<fstream.h>
#include<stdlib.h>

struct nodo{
        int f, c;
        char def[80];
        char sol[30];
        nodo *ste;
};

void inserta(nodo **cr, int f, int c, char *d, char *s);
void imprime(nodo *c);

void main()
{
        int fila, col;
        char defini[80], soluc[30];
        ifstream fe;
        nodo *crucigrama;

        fe.open("crucigrama.txt");
        if(!fe.good())
                exit(0);
        else
        {

                fe >> fila;
                fe >> col;
                fe.getline(defini,80);
                fe.getline(soluc,30);
                while(!fe.eof())
                {
                        inserta(&crucigrama, fila,col, defini, soluc);
                        fe >> fila;
                        fe >> col;
                        fe.getline(defini,80);
                        fe.getline(soluc,30);
                }
                fe.close();
                imprime(crucigrama);
        }

        cin.ignore();
        cin.get();
}


void inserta(nodo **cr, int f, int c, char *d, char *s)
{
        nodo *nuevo, *ant=*cr;
        // Primero creamos el nodo nuevo
        nuevo=new nodo;
        nuevo->f = f;
        nuevo->c = c;
        strcpy(nuevo->def, d);
        strcpy(nuevo->sol, s);

        if(*cr == NULL || ant->f >= f) //Insertamos al principio
        {
                nuevo->ste = *cr;
                *cr = nuevo;
        }
        else //Buscamos posicion
        {
                while(ant->ste!=NULL && ant->ste->f < f)
                {
                        ant = ant->ste;
                }
                nuevo->ste = ant->ste;
                ant->ste = nuevo;
        }
}

void imprime(nodo *c)
{
        while(c!=NULL)
        {
                cout << " Fila = " << c->f;
                cout << " Col = " << c->c;
                cout << " Def = " << c->def;
                cout << " Sol = " << c->sol;
                c = c->ste;
        }
}

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.

Also on Fandom

Random wikia