//链栈操作实现——创增删查
typedef struct Lnode
{
Elemtype data;
struct LNode *next;
}stack;
void add(stack *l,Elemtype x)//入栈
{
LNode *h=l,*p;
p->data=x;
p->next=l->next;
l->next=p;
}
bool StackPop(Stack l) //出栈
{
if (l->next == NULL)
{
return 0;
}
else
{
lNode *temp=l->next;
l->next=l->next->next;
print(temp->data);
free(temp);
}
return 1;
}
Elemtype StackPop(Stack l)//查询
{
if (l->next == NULL)
{
return 0;
}
else
{
return l->next->data;
}
}
//3
int judge(char a[])
{
int i=0;
int j=0,k=0;
while(a[i]!='\0')
{
switch(a[i])
{
case'I':j++;
case'O':k++;
if(k>j)
{
print("非法");
break;
}
}
i++;
}
if(j!=k)
{
print("非法");
return false;
}
else
print("合法");
return true;
}
//4
bool compareyxxy(Linklist &l,int n)
{
int i;
int a[n/2];
lNode *p=l->next;
for(i=0;i<=n/2;i++)
{
a[i]=p->data;
p=p->next;
}
i--;
if(n%2=1)
p=p->next;
while(p!=NULL&&s[i]==p->data)
{
i--;
p=p->next;
}
if(i=-1)
return 1;
else
return 0;
}
//5
#define maxsize 100
#define Elemtype int
typedef struct stack
{
Elemtype s[maxsize];
int top[2];
}stack;
int push(int i,Elemtype x)
{
if(i!=0&&i!=1)
{
print("输入error");
exit(0);
}
if(stack.top[0]+1=stack.top[1])
{
print("满了");
return 0;
}
switch(i){
case 0:stack.s[++stack.top];return 1;break;
case 1:stack.s[--stack.top];return 1;
}
}
Elemtype pop(int i)
{
if(i!=0&&i!=1)
{
print("输入error");
exit(0);
}
switch(i){
case 0:
if(stack.top[0]==-1)
{
print("空");
return -1;
}
else
return stack.s[stack.top[0]--];
case 1:
if(stack.top[1]==maxsize)
{
print("满");
return -1;
}
else
return stack.s[stack.top[1]++];
}//switch
}