zoukankan      html  css  js  c++  java
  • 栈的链表实现

    //  栈的链表实现
    #include <cstdio>
    #include <cstdlib>
    //#define _OJ_

    typedef struct Lnode
    {
        int data;
        struct Lnode *next;
    } Lnode, *stack;

    stack
    creat_list(stack s)
    {
        s = (stack) malloc (sizeof(Lnode));
        s->next = NULL;
    }

    int
    isEmpty(stack s)
    {
        if(s->next == NULL)
        return 1;
        else return 0;
    }

    void
    push(int x,stack s)
    {
        stack p;
        p = (stack) malloc (sizeof(Lnode));
        p->data = x;
        p->next = s->next;
        s->next = p;
        printf("%d ", x);
    }

    int
    pop(stack s)
    {
        int e;
        stack p;
        p = s->next;
        e = p->data;
        s->next = p->next;
        free(p);
        return e;
    }


    int main(int argc, char const *argv[]) {
    #ifndef _OJ_  //ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
    #endif

        int i, n, x;
        stack s;
        s = creat_list(s);
        printf("empty == %d ", isEmpty(s));
        scanf("%d", &n);
        for(i = 0;i < n; i++) {
        scanf("%d", &x);
        push(x,s);
         }

        for(i = 0;i < n; i++) {
        printf("pop == %d ", pop(s));
         }


        return 0;
    }




  • 相关阅读:
    Codeforces Round #417 C. Sagheer and Nubian Market
    linux 终端抓包命令
    计算机网络体系结构分析
    排序算法-快速排序
    排序算法-堆排序
    排序算法-希尔排序
    排序算法-插入排序
    排序算法-冒泡排序
    排序算法-选择排序
    杂谈:终端小工具
  • 原文地址:https://www.cnblogs.com/airfand/p/4918519.html
Copyright © 2011-2022 走看看