关闭

链式栈

105人阅读 评论(0) 收藏 举报
分类:
#include <stdio.h>
#include <Stdlib.h>
typedef struct node
{
    int data;
    struct node *pNext;
}NODE,*PNODE;
typedef struct Stack
{
    PNODE pTop;
    PNODE pBottom;
}STACK,* PSTACK;
void init(PSTACK pS)
{
    pS->pTop=(PNODE)malloc(sizeof(NODE));
    if(!pS->pTop)
        exit(0);
    pS->pBottom=pS->pTop;
    pS->pTop->pNext=NULL;
}
void push(PSTACK pS,int val)
{
    PNODE pNew=(PNODE)malloc(sizeof(NODE));
    pNew->data=val;
    pNew->pNext=pS->pTop;
    pS->pTop=pNew;
}
void traverse(PSTACK pS)
{
    PNODE p=pS->pTop;
    while(p!=pS->pBottom)
    {
        printf("%d ",p->data);
        p = p->pNext;

    }
    printf("\n");
}
int main()
{
    STACK S;
    init(&S);
    push(&S,1);
    push(&S,2);
    push(&S,32);

    push(&S,324);

    push(&S,43);

    traverse(&S);




    return 0;
}

劳资总算明白了

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:5425次
    • 积分:349
    • 等级:
    • 排名:千里之外
    • 原创:30篇
    • 转载:8篇
    • 译文:0篇
    • 评论:0条
    文章分类