#include #include #include struct node { int idata; struct node* pnext; }; char *fetchline(char *s) { /* get one line from standard input */ register int c; int n = 80; register char *pcs; pcs = s; while (--n > 0 && (c = getchar()) != EOF) if ((*pcs++ = c) == '\n') break; *pcs = '\0'; return (c == EOF && pcs == s) ? NULL : s; } int ipop(struct node ** ppnodeHead, int *piPopped) { /* pops the first value off the stack */ /*TO BE IMPLEMENTED */ *piPopped = 0; /* the value popped from the stack */ return 0; /* if successful return 0 otherwise 1 */ } void pop(struct node ** ppnodeHead) { /* pops and then prints the value on top of the stack */ int iPopped, iResult; iResult = ipop(ppnodeHead, &iPopped); if (iResult == 1) { printf("NULL\n"); } else { printf("%d\n", iPopped); } } void clear(struct node ** ppnodeHead) { /* delete everything from the stack */ printf("TO BE IMPLEMENTED\n"); } void peek(struct node * pnodeHead) { /* prints the top value of the stack. */ printf("TO BE IMPLEMENTED\n"); } void printstack(struct node * pnodeHead) { /* prints the entire stack top down. */ printf("TO BE IMPLEMENTED\n"); } void push(struct node ** ppnodeHead, int iarg) { /* push value iarg onto stack */ printf("TO BE IMPLEMENTED\n"); } void add(struct node ** ppnodeHead) { /* pops 2 values off stack; adds them; and then pushes result back on stack. It prints nothing */ printf("TO BE IMPLEMENTED\n"); } void subtract(struct node ** ppnodeHead) { /* pops 2 values off stack; Subtracts the first number popped from the second and then pushes result back on stack. It prints nothing */ printf("TO BE IMPLEMENTED\n"); } int main(int argc, char *argv[]) { struct node * pnodeHead = NULL; /*struct node * pnodeTail = NULL; */ char cline[81]; char pcOp[20]; int iarg; while(fetchline(cline)) { if (sscanf(cline, "%s", pcOp)) { if (strcmp(pcOp, "PUSH") == 0) { if (sscanf(cline, "%s %d", pcOp, &iarg)) { push(&pnodeHead, iarg); } } else if (strcmp(pcOp, "POP") == 0) { pop(&pnodeHead); } else if (strcmp(pcOp, "ADD") == 0) { add(&pnodeHead); } else if (strcmp(pcOp, "SUBTRACT") == 0) { subtract(&pnodeHead); } else if (strcmp(pcOp, "PEEK") == 0) { peek(pnodeHead); } else if (strcmp(pcOp, "PRINTSTACK") == 0) { printstack(pnodeHead); } else if (strcmp(pcOp, "CLEAR") == 0) { clear(&pnodeHead); } } } return 0; }