//顺序栈存储结构
#define Stack_Size 50
typedef struct{
type elem[Stack_Size];
int top;//栈顶元素的下标
}Stack;
//顺序栈初始化
void InitStack(Stack *S){
S->top=-1;
}
//顺序进栈
int Push(Stack *S,Type x)
{
//判满
if(S->top==Stack_Size-1) return(FLASE);
S->tp++;
S->elem[S->top]=x;
return (TRUE);
}
//顺序栈出栈
int pop(Stack *S,Type *x){
//栈顶元素弹出, x带出
//判空
if(S->top==-1) return(FLASE);
*x=S->elem[S->top];
S->top--;
return (TURE);
}
//链栈存储结构
typedef struct node{
Type data;
struct node *next;
}Node,*List;
//链栈进栈
void InitList(List L){
top=L;
top->next==NULL;
}
int push(List *L,Type x){
//申请新的空间
List *t;
t=(List *)malloc(sizeof(Node));
if(t==NULL)return(FLASE);//申请空间失败
t->data=x;
t->next=top->next;
top->next=t;
return(TURE);
}
//链栈出栈
int pop(List L,Type *x){
List t;
t=top->next;
//判空
if(t==NULL)return(FLASE);
top->next=t;//要删除的点
*x=t->data;//指针x带出
free(t);//释放指针
return (TRUE);
}
/*算法3.17 链队列插入算法
将数据元素X插入到队列中Q
*/
int EnterQueue(LinkQueue *Q,QueueElementType x){
LinkQueueNode * NewNode;
NewNode=(LinkQueueNode *)malloc(sizeof(LinkQueueNode));
if(NewNode!=NULL){
NewNode->data=x;
NewNode->next=NULL;
Q->rear->next=NewNode;//原尾指针
Q->rear=NewNode;//修改尾指针
return (TRUE);
}
else return(FALSE);
}