Description

Please write the following three functions:

請撰寫以下三個函式:

void StackPush(Stack* obj, int val): Add val as a new node to the top of the Stack.

void StackPush(Stack* obj, int val):將val做為新的節點放到Stack的頂端。

void StackPop(Stack* obj): Print and remove the top node of the Stack. If unable to remove, print 'Stack empty'.

void StackPop(Stack* obj):將Stack最頂端的節點'印出'後刪除,如果無法刪除,請印出 'Stack empty'。

void printStack(Stack* obj): Print all contents currently in the Stack starting from the top. If the Stack is empty, print 'Stack empty'.

void printStack(Stack* obj):從Stack的頂端開始印出目前Stack中的所有內容,如果 Stack 是空的,請印出 'Stack empty'。

Input

Input consists of multiple lines until EOF, each line contains the command (and required parameters).

輸入包含多行,直到EOF為止,每行包含要做的指令(以及需要的參數)。

For example: push 10, pop, printStack.

例如:push 10, pop, printStack。

Output

Refer to Description.

請參考 Description。

Sample Input 1

push 1
push -7
push 45
push 17
push -10
printStack
pop
pop
printStack
pop
pop
printStack
pop
pop
pop
printStack

Sample Output 1

-10->17->45->-7->1
45->-7->1
1
Stack empty
Stack empty
Stack empty

Given Code:

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

typedef struct stack{
    int num;
    struct stack *next;
} Stack;

Stack* StackCreate() {
    Stack* head = (Stack* )malloc(sizeof(Stack));
    head->next = NULL;
    return head;
}

void StackPush(Stack* obj, int val) {
    
}

void StackPop(Stack* obj) {
    
}

void printStack(Stack* obj){
    
}

/*
int main(){
    Stack* obj = StackCreate();
    char choice[15];
    int val;
    while (scanf("%s", choice) != EOF){
        if(strcmp(choice, "push") == 0){
            scanf("%d", &val);
            StackPush(obj, val);
        }
        else if(strcmp(choice, "pop") == 0){
            StackPop(obj);
        }
        else{
            printStack(obj);
        }
    }
}
*/

Answer BELOW