Sto facendo un programma che gestisce una lista di stringhe(un pseudo catalogo di serie tv) e ho dei problemi con la funzione che cerca la posizione in ordine alfabeticale e inserisce in ordine nella lista
codice:
void insertTVSeries(PlayList* pl, TVS* t){
TVS *tmp_prev, *tmp_next;
if(pl==NULL){//lista vuota
tmp_prev = NULL;
tmp_next = NULL;
}
else
//ricerca della posizione in cui inserire(tmp_prev e tmp_next sono due puntatori d'appoggio)
tmp_prev = NULL;
tmp_next = pl->top;
while(tmp_next != NULL && strcmp(tmp_next->title, t->title)<=0){
tmp_prev = tmp_next;
tmp_next = tmp_next->next;
}
if(tmp_next->next=NULL){
strcpy(pl->name, t->title);
pl->top->prev = pl->top;
pl->top = t;
pl->top->next = NULL;
}
else if(tmp_prev == NULL && tmp_next == NULL){
pl->top = t;
pl->top->next = NULL;
pl->top->prev = NULL;
}
else
Finora ho fatto questo ma credo che sia pieno di errori e non so come andare avanti
Le strutture usate sono queste
codice:
struct tvs
{
char title[DIM_TITLE];
char genre[DIM_GENRE];
int num_episodes;
struct tvs* prev;
struct tvs* next;
};
typedef struct tvs TVS;
struct playlist
{
char name[DIM_NAME];
TVS* top;
};
typedef struct playlist PlayList;