摘要:voidPush(Stack*S,inttheData){//將數據theData壓棧List*newNode;newNode=(List*)calloc(1,sizeof(List));newNode->data=theData;newNode->next=S->pTop;S->pTop=(3);}voidPop(Stack*S){//彈棧List*lastTop;if(IsEmpty(S))return;lastTop=S-
void Push(Stack* S, int theData) {//將數據theData壓棧
List* newNode;
newNode = (List*)calloc(1, sizeof(List));
newNode->data = theData;
newNode->next = S->pTop;
S->pTop = (3) ;
}
void Pop(Stack* S) {//彈棧
List* lastTop;
if( IsEmpty(S) ) return;
lastTop = S->pTop;
S->pTop = (4) ;
free(lastTop);
}
#define MD(a) a<<2
int main(){
int i;
Stack* myStack;
myStack = NewStack();
Push(myStack, MD(1));
Push(myStack, MD(2));
Pop(myStack);
Push(myStack, MD(3)+1);
while( !IsEmpty(myStack) ){
printf("%d ", Top(myStack));
Pop(myStack);
}
return 0;
}
以上程序運行時的輸出結果為: (5)
試題六(共15分)
閱讀下列說明和C++代碼,將應填入 (n) 處的字句寫在答題紙的對應欄內。
軟考備考資料免費領取
去領取