帮忙吧这个伪代码改成C++上课运行的代码

来源:百度知道 编辑:UC知道 时间:2024/09/22 08:21:00
题目:编写一个算法,利用堆栈结构将键盘上输入的字符串逆向输出,整个输入在遇到回车换行符('\n')时停止。
Rr_Ls(Ls_top)
{
scanf("%c",&x);
while(x!='\n')
{
Push_Ls(Ls_top,x);
scanf("%c",&x);
}
while(Ls_top!=NULL)
{
Pop_Ls(Ls_top,x);
pirntf("%c",x);
}

}
报错了奇怪

现成的有一个,不过好像结构和你的不一样,但是功能和原理一样,使用堆栈

#include<stdio.h>
#include<stdlib.h>
#define LENGTH 100

typedef struct _LIST{
int data;
struct _LIST *next;
}list,*listptr;

void createlist(list **L){
listptr p,q;
int n;
printf("Input data,-1 to end.\n");
scanf("%d",&n);

while(-1 != n){
p = (list *)malloc(sizeof(list));
p->data = n;
p->next = NULL;

if(NULL == (*L))
*L = q = p;
else{
q->next = p;
q = q->next;
}
scanf("%d",&n);
}

}

void display(list *L){
if(NULL == L){
printf("The list is NULL.\n");
return ;
}

printf("The list is:");
while(NULL != L->next){
printf("%d->",L->data);
L = L->next;
}
printf("%d.\n",L-&g