zoukankan      html  css  js  c++  java
  • LIFO栈 ADT接口 链表实现

    LIFO 链栈结构

    1 typedef int ElemType;
    2 struct node{
    3     ElemType data;
    4     struct node* next;
    5 };
    6 typedef struct node* Stack;

    LIFO 链栈基本操作

     1 //LIFO 链栈初始化
     2 void InitStack(Stack top){
     3      top = NULL;
     4 }
     5 
     6 //LIFO 链栈判断栈空
     7 boolean StackKEmpty(Stack top){
     8      if(top == NULL) return true;
     9      else return false;
    10 11 
    12 //LIFO 链栈进栈
    13 void Push(Stack 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(Stack top){
    23      LinkedStack p;
    24      ElemType x;
    25      if(top == NULL){
    26         printf("栈下溢错误!
    ");
    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(Stack top){
    38      if(top == NULL){
    39         printf("栈下溢错误! 
    ");
    40         exit(1);
    41      }
    42      return top -> data;
    43 } 
  • 相关阅读:
    python中的__init__
    python中的单例模式
    python中闭包和装饰器
    sql多表查询
    configurationChanges
    excludeFromRecents标签
    activity-alias
    meta-data
    launchMode
    Apache ant 配置
  • 原文地址:https://www.cnblogs.com/WALLACE-S-BOOK/p/9728661.html
Copyright © 2011-2022 走看看