以下是在http://tw.knowledge.yahoo.com/question/question?qid=1508080604078回答的問題

第一題
int main( ) {
push(6); //6
push(2); //6,2
pop( ); //6
push(4); //6,4
push(5); //6,4,5
pop( ); //6,4
push(pop( )+3); //6,7
push(pop( )+2); //6,9
push(7) //6,9,7
}

第二題
2.請將下列運算式分別以前序運算式及後續運算式表示。
4*(3+8)*(9-6)+8/2

              +
            /   \
        /         \
      *             ÷
    /   \          / \
  *       -        8 2
 / \     / \
4   +    9 6
   / \
   3 8
前序 +**4+38-96/82
後序 438+*96-*82/+

第三題
3.請將下列前序運算式分別以中序運算式及後序運算式表示。
-*-AB+CD/EF
           -
        /     \
     *         ÷
   /   \      / \
  -     +     E F
 / \   / \
 A B  C   D

中序 (A-B)*(C+D)-E/F
後序 AB-CD+*EF/-

第四題
4.請將下列後序運算式分別以中序運算式及前序運算式表示。
CE/F+B*DE*+
          +
        /   \
      *       *
     / \     / \
   +     B   D E
  / \
 ÷    F
/ \
C E
前序 +*+/CEFB*DE
中序 (C/E+F)*B+D*E

第五題
(1)刪除ptr
if(ptr==first)
{
 first=first->next;
}
else
{
 node* temp=first;
 while(temp->next!=ptr)
  temp=temp->next;
 temp->next=ptr->next;
}
delete ptr;

(2)刪除a增加b
node* temp=ptr->next;
ptr->next=new node;
ptr->next->next=temp->next;
delete temp;

arrow
arrow
    全站熱搜

    和風信使 發表在 痞客邦 留言(0) 人氣()