linux之服务管理与防火墙



//顺序堆栈的操作实现


void StackInitiate(SeqStack *S)
{
S->top=0;
}


int StackNotEmpty(SeqStack S)
{
if(S.top<=0)return 0;
else return 1;
}


int StackPush(SeqStack *S,DataType x)
{
if(S->top>=MaxStackSize)
{
printf("堆栈已满无法插入!\N");
return 0;
}
else
{
S->stack[S->top] = x;
S->top++;
return 1;
}
}


int StackPop(SeqStack *S,DataType *d)
{
if(S->top<=0)
{
printf("堆栈已空无数据元素出栈!\n");
return 0;
}
else
{
S->top--;
*d=S->stack[S->top];
return 1;
}
}


int StackTop(SeqStack S,DataType *d)
{
if(S.top<=0)
{
printf("堆栈已空!\n");
return 0;
}
else
{
*d=S.stack[S.top-1];
return 1;
}
}


//链式堆栈的操作实现


void StackInitiate(LSNode **head)
{
*head=(LSNode*)malloc(sizeof(LSNode));
(*head)->next=NULL;
}


int StackNotEmpty(LSNode *head)
{
if(head->next==NULL) return 0;
else return 1;
}


int StackPush(LSNode *head,DataType x)
{
LSNode *p;
p=(LSNode*)malloc(sizeof(LSNode));
p->data=x;
p->next=head->next;
head->next=p;
return 1;
}


int StackPop(LSNode *head,DataType *d)
{
LSNode *p=head->next;
if(p==NULL)
{
printf("堆栈已空出错!");
return 0;
}
head->next=p->next;
*d=p->data;
free(p);
return 1;
}


int StackTop(LSNode *head,DataType *d)
{
LSNode *p=head->next;
if(p==NULL)
{
printf("堆栈已空出错!");
return 0;
}
*d=p->data;
return 1;
}

linux之服务管理与防火墙,古老的榕树,5-wow.com

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。