主题:[原创]创建栈时出错请各位大牛指点一二!!急用!
#define MAXSIZE 10
typedef char datatype;
typedef struct{
datatype a[MAXSIZE];
int top;
}sequence_stack;
#include <conio.h>
#include<stdio.h>
#include<stdlib.h>
void huiwen(sequence_stack *list)
{
int i,j;
i=0;j=list->top-1;
if(i<j&&list->a[i]==list->a[j])
{
i++,j--;
}
else if(i<j)
printf("该数不是回文数!");
}
void init (sequence_stack *list)
{
list->top=0;
}
void create(sequence_stack *list)
{
datatype ch;
int i;
printf("输入数据,以-1结束:\n");
scanf("%c",&ch);
while(ch!=-1)
{
if(list->top==MAXSIZE)
{printf("The array is full!");exit(1);}
else{
list->a[list->top]=ch;
list->top++;
scanf("%c",&ch);}
}
printf("-----The original stack is------------");
for( i=0;i<list->top;i++)
printf("%c",list->a[i]);
printf("--------------------------------------");
}
void main()
{
int i;
sequence_stack ting;
init(&ting);
create(&ting);
printf("-----The original stack is------------");
for( i=0;i<ting.top;i++)
printf("%c",ting.a[i]);
printf("--------------------------------------");
huiwen(&ting);
for(i=0;i<ting.top;i++)
printf("%c",ting.a[i]);
}[/size][/size]
typedef char datatype;
typedef struct{
datatype a[MAXSIZE];
int top;
}sequence_stack;
#include <conio.h>
#include<stdio.h>
#include<stdlib.h>
void huiwen(sequence_stack *list)
{
int i,j;
i=0;j=list->top-1;
if(i<j&&list->a[i]==list->a[j])
{
i++,j--;
}
else if(i<j)
printf("该数不是回文数!");
}
void init (sequence_stack *list)
{
list->top=0;
}
void create(sequence_stack *list)
{
datatype ch;
int i;
printf("输入数据,以-1结束:\n");
scanf("%c",&ch);
while(ch!=-1)
{
if(list->top==MAXSIZE)
{printf("The array is full!");exit(1);}
else{
list->a[list->top]=ch;
list->top++;
scanf("%c",&ch);}
}
printf("-----The original stack is------------");
for( i=0;i<list->top;i++)
printf("%c",list->a[i]);
printf("--------------------------------------");
}
void main()
{
int i;
sequence_stack ting;
init(&ting);
create(&ting);
printf("-----The original stack is------------");
for( i=0;i<ting.top;i++)
printf("%c",ting.a[i]);
printf("--------------------------------------");
huiwen(&ting);
for(i=0;i<ting.top;i++)
printf("%c",ting.a[i]);
}[/size][/size]