首页 > 代码库 > 数据结构---栈的链表实现

数据结构---栈的链表实现

栈的链表实现C代码如下:

#include <stdio.h>

typedef int ElemType;


typedef struct node
{
    ElemType Data;
    struct node *next;
}Node;

typedef struct stack
{
    Node *top;
}Stack;

//初始化栈
void InitStack(Stack *S)
{
    S->top=NULL;
}

//入栈
int PushStackValue(Stack *S)
{
    printf("Input the Value of stack member:\n(0-exit)\n");
    int value;
    int i=1;
    Node *NewNode=(Node *)malloc(sizeof(Node));
    printf("Please input the %dst value of stack:\n",i);
    scanf("%d",&value);
    NewNode->Data=http://www.mamicode.com/value;>
运行结果:





转载请注明作者:小刘