堆栈的相关操作_链式存储

来源:互联网 发布:中教数据库 评职称 编辑:程序博客网 时间:2024/06/05 20:19
#include <bits/stdc++.h>


typedef struct  node  *pointer;
struct node
{
    int  Data;
    pointer  next;
};
typedef pointer stack;
stack Push( stack S, int  X )  /* 将元素X压入堆栈S */
{
 
    pointer    q;
    q = (pointer)malloc(sizeof(struct node));
    q->Data = X;
    q->next = S->next;
    S->next = q;
    return S;

}
int  Pop(stack S)   /* 删除并返回堆栈S的栈顶元素 */
{

    pointer  first;
    int  top;
    first = S->next;
    top = first->Data;
    S->next = first->next;
    free(first);
    return top;

}
stack  Createstack()  /* 构建一个堆栈的头结点,返回该结点指针 */
{
    stack  S;
    S = (stack)malloc(sizeof(struct node));
    S->next = NULL;
    return S;
}

int main()
{

    return 0;
}