예제 #1
0
파일: arbre.c 프로젝트: Maerig/NF16-TP5
void pre_ordre(NodePtr node)
{
    if (node->name != '\0')
    {
        printf("%c", node->name);
        pre_ordre(node->left);
        pre_ordre(node->right);
    } else
        printf("%d", node->value);
}
예제 #2
0
파일: tp5.c 프로젝트: MiLk/NF16-TP5
int main(int argc, char** argv)
{
    int n = 0, m = 0, i = 0, taille = 0;
    char v;
    NodePtr tab[50], node;
    do
    {
        printf("1- Saisir une expression\n2- Selectionner une expression\n");
        scanf("%d", &n);
        switch (n)
        {
        case 1:
            if (taille < 50)
            {
                getchar();
                node = saisie_expression();
                if(node != NULL)
                {
                    taille++;
                    tab[taille]= node;
                    affiche_expression(tab[taille]);
                }
                printf("\n\n");
            } else
                printf("Erreur. Trop d'expressions ont ete saisies.\n");
            break;
        case 2:
            if (taille > 0)
            {
                for (i = 1; i <= taille; i++)
                {
                    printf("%d- ", i);
                    affiche_expression(tab[i]);
                    printf("\n");
                }
                scanf("%d", &n);
                printf("\nFonctions a executer :\n"
                       "1- Affichage pre-ordre\n"
                       "2- Affichage in-ordre\n"
                       "3- Affichage post-ordre\n"
                       "4- Duplication\n"
                       "5- Calcul\n"
                       "6- Developpement\n"
                       "7- Derivation\n"
                       "8- Affichage\n"
                      );
                scanf("%d", &m);
                switch (m)
                {
                case 1:
                    pre_ordre(tab[n]);
                    printf("\n\n");
                    break;
                case 2:
                    in_ordre(tab[n]);
                    printf("\n\n");
                    break;
                case 3:
                    post_ordre(tab[n]);
                    printf("\n\n");
                    break;
                case 4:
                    taille++;
                    tab[taille] = clone(tab[n]);
                    printf("Nouvelle expression generee.\n\n");
                    break;
                case 5:
                    calcul(tab[n]);
                    printf("\nResultat :\n");
                    affiche_expression(tab[n]);
                    printf("\n\n");
                    break;
                case 6:
                    developpement(tab[n]);
                    printf("\nResultat :\n");
                    affiche_expression(tab[n]);
                    printf("\n\n");
                    break;
                case 7:
                    printf("\nSaisir la variable de derivation\n");
                    getchar();
                    scanf("%c", &v);
                    derivation(tab[n], v);
                    printf("\nResultat :\n");
                    affiche_expression(tab[n]);
                    printf("\n\n");
                    break;
                case 8:
                    affiche_expression(tab[n]);
                    printf("\n\n");
                    break;
                }
            } else
                printf("Aucune expression n'a ete saisie.\n");
            break;
        }
    } while (n > 0);
    for (i = 1; i <= taille; i++)
        liberer_noeud(tab[i]);
    return (EXIT_SUCCESS);
}