MERGE.c



// DEMO DEL PROYECTO 2 - ALGORITMO DE MEZCLAS

#include <stdio.h>
#include <string.h>
#include <stdlib.h>

struct nodo
{
	int numero;
	struct nodo *sig;
	struct nodo *ant;
};

struct nodo *start = NULL;


void PonEnLista(struct nodo *new)
{
	// SE INSERTAN POR LA IZQUIERDA
	if ( !start )
		start = new;
	else
	{
		new->sig = start;
		start->ant = new;
		start = new;
	}
}

void Guardar(int k)
{
	struct nodo *new = (struct nodo*)malloc(sizeof(struct nodo));
	new->numero = k;
	new->sig = new->ant = NULL;
	PonEnLista(new);
}

void MuestraLista( struct nodo *aux )
{
	while (aux)	// ¿estás apuntando a una localidad de memoria?
	{		// ¿tienes datos?
		printf("%d\n", aux->numero);
		aux = aux->sig;
	}
}

int contar( struct nodo *aux, int x )
{
	if ( !aux ) return x;
	x++; aux = aux->sig; contar(aux, x);
}

void ciclo( )
{
	int n=9, V[10] = {"45","67","8","9","uno","dos","2","tres","siete"};
	while (n != 0) { Guardar( V[n-1] ); n--; }
}



int main(int o, char **l)
{
	int mitad=0;
	ciclo(); MuestraLista(start);
	//printf("cantidad= %d\n", contar(start, 0));
	mitad = contar(start, 0)/2;
	creaLista(mitad, start);
}