posts - 0,comments - 0,trackbacks - 0
#include<iostream>
using namespace std;
typedef struct LNode
{
    int data;
    struct LNode *next;
}LNode;
void initStack(LNode *&list)
{
    list=(LNode*)malloc(sizeof(LNode));
    list->next=NULL;
}
int isEmpty(LNode *lst)
{
    if(lst->next==NULL)
        return 1;
    else
        return 0;
}
void push(LNode *&lst,int x)
{
    LNode *p;
    p=(LNode*)malloc(sizeof(LNode));
    p->next=NULL;
    
    p->data=x;
    p->next=lst->next;
    lst->next=p;
}
int pop(LNode *&lst,int &x)
{
    LNode *p;
    if(lst->next==NULL)
        return 0;
    p=lst->next;
    x=p->data;
    lst->next=p->next;
    free(p);
    return 1;
}
int main()
{
    LNode *head;
    initStack(head);
    push(head,5);
    push(head,6);
    int x;
    pop(head,x);
    cout<<x<<endl;
    return 0;
}
posted on 2012-08-22 08:14 yyj 阅读(202) 评论(0)  编辑 收藏 引用

只有注册用户登录后才能发表评论。
网站导航:   博客园   博客园最新博文   博问   管理