#include <iostream>
#include "lianzhandetouwenjian.h"
using namespace std;
void shuchulianzhan(linkstnode * s)
{
linkstnode * p=s->next;
while(p!=NULL)
{
cout<<p->shuju<<" ";
p=p->next;
}
cout<<endl;
}
int main()
{
linkstnode * s;
A e;
int i=0;
lianzhanchushihua(s);
cout<<lianzhanpanduankong(s)<<endl;
e='a';
jinlianzhan(s,e,i);
e='b';
jinlianzhan(s,e,i);
e='c';
jinlianzhan(s,e,i);
e='d';
jinlianzhan(s,e,i);
e='e';
jinlianzhan(s,e,i);
cout<<lianzhanpanduankong(s)<<endl;
cout<<lianzhanchangdu(s)<<endl;
shuchulianzhan(s);
for(int a=0;a<5;a++)
{
chulianzhan(s,e);
cout<<e<<" "<<i<<endl;
i--;
}
cout<<lianzhanpanduankong(s)<<endl;;
cuihuilianzhan(s);
return 0;
}
#include <iostream>
#include <malloc.h>
#include "lianzhandetouwenjian.h"
void lianzhanchushihua(linkstnode *& s)
{
s=(linkstnode *)malloc(sizeof(linkstnode));
s->next=NULL;
}
void cuihuilianzhan(linkstnode *& s)
{
linkstnode * pre=s,*p=s->next;
while(p!=NULL)
{
free(pre);
pre=p;
p=pre->next;
}
free(pre);
}
bool lianzhanpanduankong(linkstnode * s)
{
return(s->next==NULL);
}
void jinlianzhan(linkstnode *& s,A e,int &i)
{
linkstnode * p;
p=(linkstnode *)malloc(sizeof(linkstnode));
p->shuju=e;
p->next=s->next;
s->next=p;
i++;
}
bool chulianzhan(linkstnode *& s,A &e)
{
linkstnode * p;
if(s->next==NULL)
return false;
p=s->next;
e=p->shuju;
s->next=p->next;
free(p);
return true;
}
bool qulianzhanding(linkstnode * s,A &e)
{
if(s->next==NULL)
return false;
e=s->next->shuju;
return true;
}
int lianzhanchangdu(linkstnode * s)
{
int i=0;
linkstnode * p=s->next;
if(p==NULL)
return 0;
while(p!=NULL)
{
i++;
p=p->next;
}
return i;
}
#ifndef LIANZHANDETOUWENJIAN_H_INCLUDED
#define LIANZHANDETOUWENJIAN_H_INCLUDED
typedef char A;
typedef struct linknode
{
A shuju;
struct linknode * next;
}linkstnode;
void lianzhanchushihua(linkstnode *& s);
void cuihuilianzhan(linkstnode *& s);
bool lianzhanpanduankong(linkstnode * s);
void jinlianzhan(linkstnode *& s,A e,int &i);
bool chulianzhan(linkstnode *& s,A &e);
bool qulianzhanding(linkstnode * s,A &e);
int lianzhanchangdu(linkstnode * s);
#endif // LIANZHANDETOUWENJIAN_H_INCLUDED