Esempio n. 1
0
File: main.c Progetto: vlnk/isima
int main(int argc, char ** argv)
{
    /*variables locales*/
    lifo_t *    p = NULL;       /*pile*/
    int         err = TRUE;     /*erreur d'allocation*/

    /*test des arguments*/
    if (argc < 2)
    {
        printf("USAGE %s <chaine a inverser>\n",argv[0]);
    }
    else
    {
        /*initialisation*/
        p = (lifo_t *)malloc(sizeof(lifo_t));
        err = init_lifo(p,TMAX);

        if (!err && p)
        {
            lecture_pile(p,argv[1]);
            inversion_pile(p);

            /*liberation des ressources*/
            free_lifo(p);
            p = NULL;
        }
    }
    return 0;
}
Esempio n. 2
0
int main( /* int argc, char const *argv[] */ )
{
	printf("Projet Monoplan, Lenouvel Baptiste\n\n");

	printf("======== TEST LIFO ========\n\n");

	lifo_t stack;

	init_lifo(&stack, STACK_SIZE);
	
	printf("Push 42\n");
	push(&stack, 42.0);

	printf("Push 1337\n");
	push(&stack, 1337.0);

	printf("Push 31137\n");
	push(&stack, 31337.0);
	
	printf("pop : %lf \n", pop(&stack));
	printf("pop : %lf \n", pop(&stack));
	printf("pop : %lf \n", pop(&stack));
	printf("pop : %lf \n", pop(&stack));
	printf("pop : %lf \n", pop(&stack));

	free_lifo(&stack);

	printf("\n======== TEST QUEUE ======== \n\n");

	queue_t * queue;

	int test = 1337;
	char * str = "apprenti";
	char * str1 = "loick_et_ses_poules";
	char * str2 = "limousin";
	char * str3 = "ZZtop";

	printf("Init queue : ");
	init_queue(&queue);
	printf("ok\n\n");

	printf("Push %s \n", str);
	q_push(&queue, str);

	printf("Push %s \n", str1);
	q_push(&queue, str1);

	printf("Push in head : %d \n", test);
	q_push_head(&queue, &test);

	printf("Push in head : %s \n\n", str2);
	q_push_head(&queue, str2);


	printf("Removing %s ... %s \n\n", str2, q_remove(&queue, str2) ? "ok" : "ko");

	// printf("Pop head : %s \n", (char *)(q_pop_head(&queue)) );
	printf("Pop head : %d \n", *(int *)(q_pop_head(&queue)) );
	printf("Pop head : %s \n", (char *)(q_pop_head(&queue)) );
	printf("Pop head : %s \n\n", (char *)(q_pop_head(&queue)) );

	printf("Push %s with q_operation \n\n", str3);
	q_operation(&q_push, &queue, str3);

	q_free(&queue);

	return 0;
}