#include<stdlib.h> #include<stdio.h> typedef struct LinkNode{ LinkNode *next; int data; }LinkNode; typedef struct Stack{ LinkNode*node; }Stack; Stack InitStack() { LinkNode*head = (LinkNode*)malloc(sizeof(LinkNode)) ; head->next=NULL; Stack s ; s.node = head; return s; } void Destroy(Stack *s) { if (s==NULL||s->node ==NULL) { return ; } LinkNode *p = s->node->next; while (p!=NULL) { LinkNode*q = p; s->node->next=p->next; p=p->next; free(q); q=NULL; } free(s->node); s->node = NULL; } void PrintStack(Stack *s) { if (s==NULL||s->node ==NULL) { return ; } LinkNode *p = s->node->next; while (p!=NULL) { printf("%d",p->data); p=p->next; } } void ClearSatck(Stack *s) { if (s==NULL||s->node ==NULL) { return ; } LinkNode *p = s->node->next; while (p!=NULL) { LinkNode*q = p; s->node->next=p->next; p=p->next; free(q); q=NULL; } } bool IsEmpty(Stack *s) { if (s==NULL||s->node ==NULL) { return true; } if (s->node->next==NULL) { return true; } return false; } void PushStack(Stack *s,int val)//t { if (s==NULL||s->node ==NULL){ return ; } LinkNode *q = (LinkNode *)malloc(sizeof(LinkNode)); q->data = val; q->next =s->node->next; s->node->next = q; } bool PopStack(Stack *s,int*e)//t { if (s==NULL||s->node ==NULL||s->node->next ==NULL){ return false; } *e = s->node->next->data; LinkNode *p=s->node->next; s->node->next = p->next; free(p); p=NULL; return true; } int TopStack(Stack *s) { if (s==NULL||s->node ==NULL|| s->node->next==NULL) { return -1; } return s->node->next->data; } int GetMinVal(){ Stack s = InitStack(); Stack minStack = InitStack(); int minVal=0; for (int i=0;i<10;i++) { if (i<minVal){ minVal=i; } PushStack(&minStack,minVal); PushStack(&s,i); } PrintStack(&s); printf("\n"); PrintStack(&minStack); printf("\n"); return TopStack(&minStack); }