®(\ 256)字符在c ++中

时间:2017-03-28 21:27:14

标签: c

在c语言中的含义是什么,在此代码中,由于®,在打印部分的程序中出现[错误]错误'\ 256'的错误。和我 想翻译c ++代码。虽然如此,我们[错误]从'void *'无效转换为'node *'[-fpermissive]

#include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include <ctype.h>

    #define MAX 10
    #define EMPTY -1

    struct node
    {
        char kind;
        char op;
        int number;
        struct node *left,*right;
    };

    struct stack
    {
        struct node *data[MAX];
        int top;
    };

    int isempty(struct stack *s)
    {
        return (s->top == EMPTY) ? 1 : 0;
    }

    void emptystack(struct stack* s)
    {
        s->top=EMPTY;
    }

    void push(struct stack* s, struct node *item)
    {
        if(s->top == (MAX-1))
        {
            printf("\nSTACK FULL");
        }
        else
        {
            ++s->top;
            s->data[s->top]=item;

        }
    }

    struct node* pop(struct stack* s)
    {
        struct node *ret=NULL;
        if(!isempty(s))
        {
            ret= s->data[s->top];
            --s->top;
        }
        return ret;
    }

    void postfix2exptree(char* postfix, struct node **root)
    {
        struct stack X;
        struct node *newnode,*op1,*op2;
        char numberextract[5];
        char *p;

        emptystack(&X);
        p = &postfix[0];
        strcpy(numberextract,"");
        while(*p)
        {

            while(*p == ' ' || *p == '\t')
            {
                p++;
            }

            if(isdigit(*p))
            {
                while(isdigit(*p))
                {
                    strcat(numberextract,p);
                    p++;
                }

                newnode = malloc(sizeof(struct node));
                newnode->kind = 'N';
                newnode->number = atoi(numberextract);
                newnode->left = NULL;
                newnode->right = NULL;
                push(&X,newnode);
                strcpy(numberextract,"");
            }
            else
            {
                op1 = pop(&X);
                op2 = pop(&X);
                newnode = malloc(sizeof(struct node));
                newnode->kind = 'O';
                newnode->op = *p;
                newnode->left = op2;
                newnode->right = op1;
                push(&X,newnode);
            }
            p++;
        }
        *root = pop(&X);
    }

    int evaluatetree(struct node *x)
    {
       if( x->kind == 'O' )
        {
          int op1 = evaluatetree( x->left );
          int op2 = evaluatetree( x->right );
          switch ( x->op )
            {
             case '+':  return op1 + op2;
             case '-':  return op1 - op2;
             case '*':  return op1 * op2;
             case '/':  return op1 / op2;
             default:   return 0;
          }
       }
        else
           return (x->number);
    }

    void inorder(struct node *x)
    {
        if(x != NULL)
        {
            inorder(x->left);

            if(x->kind == 'O')
                printf("%c ",x->op);
            else
                printf("%d ",x->number);

            inorder(x->right);
        }
    }

    void preorder(struct node *x)
    {
        if(x != NULL)
        {
            if(x->kind == 'O')
                printf("%c ",x->op);
            else
                printf("%d ",x->number);

            preorder(x->left);
            preorder(x->right);
        }
    }

    void postorder(struct node *x)
    {
        if(x != NULL)
        {
            postorder(x->left);
            postorder(x->right);

            if(x->kind == 'O')
                printf("%c ",x->op);
            else
                printf("%d ",x->number);
        }
    }

    int main()
    {
        struct node *r;
        postfix2exptree("100 50 - 2 /",&r);
        printf("Inorder = ");
        *inorder®;
        printf("\nPreorder = ");
        preorder®;
        printf("\nPostprder = ");
        postorder®;
        printf("\nResult = %d\n",evaluatetree®);
        return 0;
    }

1 个答案:

答案 0 :(得分:2)

这是&#34; smart&#34;文字编辑。

代码应该是:

Q(group__id=1) & Q(group_id=2) &

其中inorder(r); printf("\nPreorder = "); preorder(r); r

原作者粘贴文字并且没有检查,智能文本编辑将(r)转换为版权符号。

请注意,struct node *inorder是代码中前面定义的函数。