#include<iostream>
#include<stdio.h>
#include<string.h>
#include<conio.h>
using namespace std;
typedef struct student
{
int data;
struct student *next;
}node;
typedef struct stackqueue
{
node *base,*top;
}queue;
//入栈
queue *push(queue *HQ,int x)
{
node *s,*p;
s = (node *)malloc(sizeof(node));
s->data = x;
s->next = NULL;
if(HQ->base == NULL)
{
HQ->base = s;
HQ->top = s;
}
else
{
HQ->top->next = s;
HQ->top = s;
}
return(HQ);
}
//出栈
queue *pop(queue *HQ)
{
node *p;int x;
if(HQ->base == NULL)
{
printf("\n yichu");
}
else
{
x = HQ->base->data;
p = HQ->base;
if(HQ->base == HQ->top)
{
HQ->base = NULL;
HQ->top = NULL;
}
else{
while(p->next!=HQ->top)
{
p = p->next;
}
HQ->top = p;
HQ->top->next = NULL;
}
return(HQ);
}
}
栈的操作
最新推荐文章于 2023-03-24 13:30:47 发布