void print_inc(LL p){ if(!p){ return; } print_inc(p->_next); printf("%d\t",p->_value); }
void test(){ LL tab1 = NULL; int tab[N]={12,2,0,3,55,88,42,26,17,8}; int i; for (i=9;i>=0;i--){ add_queue(&tab1,tab[i]); } display_size(tab1); printf("\n"); print_inc(tab1); printf("\n"); printf("Valeur max de la liste: %d\n", maximum(tab1)); printf("\n"); printf("Valeur min de la liste: %d\n", minimum(tab1)); printf("\n"); printf("Tri de la liste: \n"); sort_ascending(tab1); printf("\n"); if(delete_list(tab1)==NULL){ printf("Linked list has been deleted.\n"); } }
/* * helper functions to print instructions */ void print_fop(struct filter_op *fop, u_int32 eip) { switch (fop->opcode) { case FOP_TEST: print_test(fop, eip); break; case FOP_ASSIGN: print_assign(fop, eip); break; case FOP_INC: print_inc(fop, eip); break; case FOP_DEC: print_dec(fop, eip); break; case FOP_FUNC: print_function(fop, eip); break; case FOP_JMP: fprintf(stdout, "%04lu: JUMP ALWAYS to %04d\n", (unsigned long)eip, fop->op.jmp); break; case FOP_JTRUE: fprintf(stdout, "%04lu: JUMP IF TRUE to %04d\n", (unsigned long)eip, fop->op.jmp); break; case FOP_JFALSE: fprintf(stdout, "%04lu: JUMP IF FALSE to %04d\n", (unsigned long)eip, fop->op.jmp); break; case FOP_EXIT: fprintf(stdout, "%04lu: EXIT\n", (unsigned long)eip); break; default: fprintf(stderr, "UNDEFINED OPCODE (%d) !!\n", fop->opcode); exit(-1); break; } }
double sort_ascending(LL p){ int max; LL tmp3=(LL)malloc(sizeof(LL)); LL tmp1=(LL)malloc(sizeof(LL)); LL tmp=p; for(tmp=p ; tmp!=NULL ; tmp=tmp->_next){ tmp3=tmp; max=tmp->_value; for(tmp1=tmp->_next ; tmp1!=NULL ; tmp1=tmp1->_next){ if(max < tmp1->_value){ tmp3=tmp1; //Tmp3 est l'adresse de l'element ou se trouve le max. max=tmp3->_value; } } tmp3->_value=tmp->_value; //Echange des 2 elements. tmp->_value=max; print_inc(p); //Affiche les etapes du tri. } }