zoukankan      html  css  js  c++  java
  • 链栈

    #include "stdafx.h"
    #include<iostream>
    
    typedef int ElemType;
    using namespace std;
    
    typedef struct stacknode {
        ElemType data;
        struct stacknode * next;
    }StackNode;
    
    typedef struct {
        StackNode *top;
    }LinkStack;
    
    LinkStack *InitStack() {
        LinkStack *s;
        s = (LinkStack*)malloc(sizeof(LinkStack));
        s->top = NULL;
        return s;
    }
    
    void Push_LinkStack(LinkStack*s, ElemType elem) {
        StackNode *p;
        p = (StackNode*)malloc(sizeof(StackNode));
        p->next = s->top;
        p->data = elem;
        s->top = p;
    }
    
    int Pop_LinkStack(LinkStack *s, ElemType *elem) {
        StackNode *p;
        if (s->top == NULL) return 0;
        else {
            p = s->top;
            *elem = p->data;
            s->top = p->next;
            free(p);
            return 1;
        }
    }
    
    int main() {
        LinkStack *s = InitStack();
        int e=0;
        for (int i = 0; i < 5; i++) {
            cin >> e;
            Push_LinkStack(s, e);
        }
        ElemType item;
        Pop_LinkStack(s, &item);
        cout << item<<endl;
    
        system("pause");
        return EXIT_SUCCESS;
    }
  • 相关阅读:
    adb
    js百分比
    隐私策略
    JSON.parse&JSON.stringify
    MVC内容backgroundimage: url('')问题
    mvc笔记
    winform路径
    配置
    邮件发送的原理
    如何调试Windows服务
  • 原文地址:https://www.cnblogs.com/linkmust/p/10915512.html
Copyright © 2011-2022 走看看