标签:栈结构 bool null eof oid 链表 struct pre def
LIFO 链栈结构
1 typedef int ElemType; 2 struct node{ 3 ElemType data; 4 struct node* next; 5 }; 6 typedef struct node* LinkedStack;
LIFO 链栈基本操作
1 //LIFO 链栈初始化 2 void InitStack(LinkedStack top){ 3 top = NULL; 4 } 5 6 //LIFO 链栈判断栈空 7 boolean StackKEmpty(LinkedStack top){ 8 if(top == NULL) return true; 9 else return false; 10 } 11 12 //LIFO 链栈进栈 13 void Push(LinkedStack top, ElemType x){ 14 LinkedStack p; 15 p = malloc(sizeof *p); 16 p -> data =x; 17 p -> next = top; 18 top = p; 19 } 20 21 //LIFO 链栈出栈 22 ElemType Pop(LinkedStack top){ 23 LinkedStack p; 24 ElemType x; 25 if(top == NULL){ 26 printf("栈下溢错误!\n"); 27 exit(1); 28 } 29 p = top; 30 x = p -> data; 31 top = top -> next; 32 free(p); 33 return x; 34 } 35 36 //LIFO 链栈读取栈顶 37 ElemType GetTop(LinkedStack top){ 38 if(top == NULL){ 39 printf("栈下溢错误! \n"); 40 exit(1); 41 } 42 return top -> data; 43 }
标签:栈结构 bool null eof oid 链表 struct pre def
原文地址:https://www.cnblogs.com/WALLACE-S-BOOK/p/9728661.html