求数据结构栈简单程序,送300积分
来源:百度知道 编辑:UC知道 时间:2024/05/21 09:34:25
可以参考我的算法
方法1:非递归算法:
staitic noss(&s)
{ int c=0;
while(s.top!=s.base) { c++; pop(s);}
return c; }
方法2:递归算法:
static nos2(&s)
{ if (gettop(s)!=NULL) { pop(s); nos2=1+nos2(s); }
else nos2=0;
}
#include <stdio.h>
#include <malloc.h>
#include <iostream.h>
struct SeqStack
{
int MAXNUM;
int t;
int *s;
};
typedef struct SeqStack * PSeqStack;
PSeqStack createEmptyStack_seq(int m)
{
PSeqStack pastack =(PSeqStack)malloc(sizeof(struct SeqStack));
if(pastack!=NULL)
{
pastack->s=(int *)malloc(sizeof(int)*m);
pastack->t=-1;
pastack->MAXNUM=m;
return(pastack);
}
else
printf("Overflow!\n");
return(NULL);