主题:栈问题
/* Note:Your choice is C IDE */
#include "stdio.h"
#define max 6
typedef struct stack{
char ch[max];
int top;
}stack;
//初始化
stack *initiatels()
{
stack *head;
head=(stack *)malloc(sizeof(stack));
head->top=-1;
return head;
}
//进栈
void instack(stack *head)
{
char m;
while(head->top<max)
{
head->top++;
m=getchar();
head->ch[head->top]=m;
}
}
//出栈
void outstack(stack *head)
{
while(head->top>0)
{
printf("%c",head->ch[head->top]);
head->top--;
}
}
void main()
{
stack *head;
head=initiatels();
instack(head);
outstack(head);
}
有谁能够告诉一下,这错在哪里呢
#include "stdio.h"
#define max 6
typedef struct stack{
char ch[max];
int top;
}stack;
//初始化
stack *initiatels()
{
stack *head;
head=(stack *)malloc(sizeof(stack));
head->top=-1;
return head;
}
//进栈
void instack(stack *head)
{
char m;
while(head->top<max)
{
head->top++;
m=getchar();
head->ch[head->top]=m;
}
}
//出栈
void outstack(stack *head)
{
while(head->top>0)
{
printf("%c",head->ch[head->top]);
head->top--;
}
}
void main()
{
stack *head;
head=initiatels();
instack(head);
outstack(head);
}
有谁能够告诉一下,这错在哪里呢