标签:struct int col tac 语言 malloc sizeof pre ==
链栈与链表结构相似
1 typedef int elemtype; 2 3 typedef struct linkedStackNode{ 4 elemtype e; 5 struct linkedStackNode *next; 6 }LinkedStack; 7 8 LinkedStack *init_LinkedStack(){ 9 10 LinkedStack *top = (LinkedStack *)malloc(sizeof(LinkedStack)); 11 if(top==NULL) 12 return NULL; 13 14 top->next = NULL; 15 return top; 16 17 }
链栈的入栈和链表的前插法一模一样。
1 int Push_LinkedStack(LinkedStack *top,elemtype e){ 2 3 LinkedStack *p = (LinkedStack *)malloc(sizeof(LinkedStack)); 4 if(p==NULL) 5 return 0; 6 7 p->e = e; 8 p->next = top->next; 9 top->next = p; 10 return 1; 11 12 }
出栈
1 int Pop_LinkedStack(LinkedStack *top,elemtype &e){ 2 3 if(top->next==NULL) 4 return 0; 5 6 LinkedStack *p = top->next; 7 &e = p->e; 8 top->next = p->next; 9 free(p); 10 return 1; 11 12 }
标签:struct int col tac 语言 malloc sizeof pre ==
原文地址:https://www.cnblogs.com/lsy-lsy/p/10027829.html