|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
- #include<stdio.h>
- #include<malloc.h>
- typedef char datetype;
- typedef struct node
- {
- datetype date;
- struct node *p;
- } LSstack;
- void LSstack_initialize(LSstack** headpoint);
- int LSstack_notempty(LSstack* headpoint);
- void LSstack_push(LSstack **headpoint, datetype);
- int LSstack_pop(LSstack** headpoint, datetype*);
- int LSstack_top(LSstack* headpoint, datetype*);
- void LSstack_initialize(LSstack** S)
- {
- (*S) = (LSstack*)malloc(sizeof(LSstack));
- (*S)->p = NULL;
- }
- int LSstack_notempty(LSstack* S)
- {
- if ((S->p) != NULL)
- return 0;
- else return 1;
- }
- void LSstack_push(LSstack **S, datetype a)
- {
- if ((*S)->p = NULL)
- {
- (*S)->date = a;
- }
- else
- {
- LSstack* m_p;
- m_p = (*S);
- (*S) = (LSstack*)malloc(sizeof(LSstack));
- (*S)->p = m_p;
- (*S)->date = a;
- }
- }
- int LSstack_pop(LSstack** S, datetype *d)
- {
- if ((*S) == NULL)
- return 0;
- else
- {
- LSstack* m_p;
- m_p = (*S)->p;
- *d = (*S)->date;
- free(*S);
- (*S) = m_p;
- return 1;
- }
-
- }
- int LSstack_top(LSstack* S, datetype *d)
- {
- if(S == NULL)
- {
- printf("error");
- return 0;
- }
- *d = S->date;
- return 1;
- }
复制代码
求大佬帮我看看这栈问题出在哪 测试了一下好像不能存超过两个数 |
|