Lo que intento hacer es que al ir agregando se vayan ordenando los datos
Pero tengo problemas con el ultimo caso, como hago la comparacion y como voy avanzando si lo tengo que hacer de forma recursiva??
Código
#include <stdio.h> #include <stdlib.h> #include <string.h> #define SALIR 0 typedef struct nodo { int dato; struct nodo *sig; struct nodo *ant; }NODO; typedef struct punteros { struct nodo *inicio; struct nodo *fin; }LISTA; int agregar_ordenado(LISTA *aux, int dato) { if(aux->inicio==NULL)//LISTA VACIA { nuevo->dato=dato; nuevo->ant=nuevo; nuevo->sig=nuevo; aux->fin=nuevo; aux->inicio=nuevo; return 1; } if(dato > aux->inicio->dato)//ES MAYOR AL INICIO { nuevo->dato=dato; nuevo->sig=aux->inicio; aux->inicio->ant=nuevo; aux->inicio=nuevo; nuevo->ant=aux->fin; aux->fin->sig=aux->inicio; return 1; } if(dato < aux->fin->dato)//ES MENOR AL FIN { nuevo->dato=dato; nuevo->ant=aux->fin;in aux->fin->sig=nuevo; nuevo->sig=aux->inicio; aux->inicio->ant=nuevo; return 1; } if()//EN MEDIO DE LA LISTA { } agregar_ordenado(aux->inicio->sig) } void imprimir(LISTA *aux)//DEL ULTIMO AREGADO AL PRIMERO { NODO *actual; actual = aux->inicio; while(actual != aux->fin) { actual = actual->sig; } } int main() { NODO *lista =NULL; int op,dat,num; aux->inicio = NULL; aux->fin = NULL; do { switch(op) { case 0: case 1: agregar_ordenado(aux,dat); break; case 2: imprimir(aux); break; } }while(op!=SALIR); return 0; }