题目:用单链表实现任意两个一元多项式的加、减法运算

1个回答

  • #include

    #include

    #include

    #define N 7

    typedef enum { add, nul, sub, div1, yu, l, r }OP;

    int a[N][N] = {

    { 0, 0, -1, -1, -1, 1, 2 },

    { 0, 0, -1, -1, -1, 1, 2 },

    { 1, 1, 0, 0, 0, 1, 2 },

    { 1, 1, 0, 0, 0, 1, 2 },

    { 1, 1, 0, 0, 0, 1, 2 },

    };

    int top;

    OP beg;

    int b[1024];

    OP op[1024];

    void init_nu( ){ top = 0; }

    void push_nu( int term ){ b[top++] = term; }

    int pop_nu( ){ return b[--top]; }

    int is_empty_nu( ){ return top == 0; }

    void destory_nu( ) { top = 0; }

    void init_sign( ){ beg = 0; }

    void push_sign( OP sign ){ op[beg++] = sign; }

    void destory_sign( ){ beg = 0; }

    OP pop_sign( ){ return op[--beg];}

    OP get_sign( ){ return op[beg - 1]; }

    int is_empty_sign( ){return beg == 0; }

    int eval()

    {

    int i, j;

    i = pop_nu();

    j = pop_nu();

    switch( pop_sign() )

    {

    case '+': push_nu( j + i ); break;

    case '-': push_nu( j - i ); break;

    case '*': push_nu( j * i ); break;

    case '/': push_nu( j / i ); break;

    case '%': push_nu( j & i ); break;

    defult: break;

    }

    }

    int change( char *s )

    {

    int i;

    int n = strlen( s );

    for( i = 0; i < n; i++ )

    {

    if( s[i] >= '0' && s[i] = '0' && s[i]