一个很简单的程序,能运行却没结果,请高手帮帮忙!
//设A=(a1,a2...,an)和B=(b1,b2...,bn)均为顺序表,比较A与B大小#include <stdio.h>
#include <stdlib.h>
#define LIST_INIT_SIZE 100
#define LISTINCREMENT 10
#define OVERFLOW 0
#define LEN sizeof(Sqlist)
typedef struct {
char * elem;
int length;
int listsize;
}Sqlist;
void InitList_Sq(Sqlist &L) {
/*构造一个空的线性表*/
L.elem=(char *)malloc(LIST_INIT_SIZE * sizeof(char));
if (!L.elem) exit(OVERFLOW);
L.length = 0;
L.listsize = LIST_INIT_SIZE;
return;
} /*InitList_Sq*/
void Comparison_Sq(Sqlist A, Sqlist B) {
int i = 0;
while( i < A.length && i < B.length )
{
if( A.elem[i] < B.elem[i] )
{
printf("A < B\n");
}
else if( A.elem[i] > B.elem[i] )
printf("A > B\n");
else
i ++;
}
if(A.length < B.length )
{
printf("A < B\n");
}
else if ( A.length > B.length )
{
printf("A > B");
}
else
{
printf("A == B");
}
}
void main()
{
Sqlist A,B;
int i=0,j=0;
char flag;
InitList_Sq(A); //构造空表A
InitList_Sq(B); //构造空表B
printf("请输入A的字母序列:\n");
while(scanf("%c",&flag),A.listsize>=i) {
if (flag == '\n') break;
else {
A.elem[i]=flag;
flag = NULL;
A.length++;
i++;
}
}
printf("请输入B的字母序列:\n");
while(scanf("%c",&flag),B.listsize>=j) {
if (flag == '\n') break;
else {
B.elem[j]=flag;
flag = NULL;
B.length++;
j++;} }
/*比较:*/
Comparison_Sq(A,B);
}