大神们,C语言的一个程序,帮我看看该怎么改,谢谢了。这是用的栈里面的链表,达到先进先出的要求。
a.h中的内容如下:#ifndef__WORD__#define__WORD__typedefstructword{chararr;structword*next;}Wo...
a.h中的内容如下:
#ifndef __WORD__
#define __WORD__
typedef struct word
{
char arr;
struct word *next;
}Word;
Word *create();
int add(Word **ch,char c);
int show(Word *ch);
#endif
main.c中的内容如下:
#include "a.h"
#include <stdio.h>
int main(int argc,char *argv[])
{
Word *p;
p = create();
add(&p,'a');
add(&p,'b');
show(p);
}
下面是a.c中的内容:
#include "a.h"
#include <stdio.h>
#include <stdlib.h>
Word *create()
{
Word *ch = (Word *)malloc(sizeof(Word));
ch -> next = NULL;
return ch;
}
int add(Word **p,char c)
{
Word *q = (Word *)malloc(sizeof(Word));
q -> next = *p;
q -> arr = c;
(*p) -> next = q;
return 0;
}
int show(Word *ch)
{
Word *L = ch;
while(L -> next)
{
printf("%c\n",L -> arr);
L = L -> next;
}
return 0;
}
标题上说错了,是先进后出 展开
#ifndef __WORD__
#define __WORD__
typedef struct word
{
char arr;
struct word *next;
}Word;
Word *create();
int add(Word **ch,char c);
int show(Word *ch);
#endif
main.c中的内容如下:
#include "a.h"
#include <stdio.h>
int main(int argc,char *argv[])
{
Word *p;
p = create();
add(&p,'a');
add(&p,'b');
show(p);
}
下面是a.c中的内容:
#include "a.h"
#include <stdio.h>
#include <stdlib.h>
Word *create()
{
Word *ch = (Word *)malloc(sizeof(Word));
ch -> next = NULL;
return ch;
}
int add(Word **p,char c)
{
Word *q = (Word *)malloc(sizeof(Word));
q -> next = *p;
q -> arr = c;
(*p) -> next = q;
return 0;
}
int show(Word *ch)
{
Word *L = ch;
while(L -> next)
{
printf("%c\n",L -> arr);
L = L -> next;
}
return 0;
}
标题上说错了,是先进后出 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询