zoukankan      html  css  js  c++  java
  • 链式栈

    #include <iostream>
    using namespace std;
    
    
    typedef struct listnode
    {
        int data;
        struct listnode *next;
    }LIST_NODE;
    
    
    typedef struct list
    {
        LIST_NODE* top;
    }LIST;
    
    
    LIST* create_list()
    {
        LIST* list = new (LIST);
        list->top = NULL;
        return list;
    }
    
    LIST_NODE* create_node(int data, LIST_NODE* next)
    {
        LIST_NODE* node = new (LIST_NODE);
        node->data =data;
        node->next = next;
        return node;
    }
    
    
    void list_push(LIST* list, int data)
    {
        list->top = create_node(data,list->top);
    }
    
    
    LIST_NODE* destroy_node(LIST_NODE* node)
    {
        LIST_NODE* next = node->next;
        delete(node);
        return next;
    }
    
    
    int list_pop(LIST* list)
    {
        int data=list->top->data;
        list->top = destroy_node(list->top);
        return data;
    }
    void destroy_list(LIST* list)
    {
        while(list->top)
        {
            list->top = destroy_node(list->top);
        }
       delete list;
    }
    
    
    bool empty_list(LIST* list)
    {
        if(NULL==list->top)
        {
            return true;
        }
        else
        {
            return false;
        }
    }
    
    
    bool full_list(LIST* list)
    {
        return false;
    }
    
    
    int main()
    {
        LIST* list = create_list();
        for(int i=10;i<=100;i+=10)
        {
            list_push(list,i);
        }
        while(! empty_list(list))
        {
            cout<<list_pop(list)<<endl;
        }
    
    
        destroy_list(list);
        return 0;
    }

    关注公众号 海量干货等你
  • 相关阅读:
    hdu 2106 decimal system
    00-自测4. Have Fun with Numbers (20)
    07-图4. Saving James Bond
    hdu 2209 翻纸牌游戏
    hdu 1272 小希的迷宫
    1969 Pie
    怎样维护 SQLite
    Navicat使用亮点
    Navicat for MySQL 11 Mac安装教程
    Navicat for PostgreSQL 运算符有哪些类别
  • 原文地址:https://www.cnblogs.com/sowhat1412/p/12734512.html
Copyright © 2011-2022 走看看