#include
<
stdio.h
>
#include < stdlib.h >
#include < string .h >
#define MAXSIZE 100
typedef int DataType;
typedef struct
{
DataType data[MAXSIZE];
int last;
}seqlist;
seqlist * Creat_seqlist()
{
int n;
seqlist * L;
L = (seqlist * )malloc( sizeof (seqlist));
L -> last =- 1 ;
printf( " 请输入创建的线性表的数据元素的个数:\n " );
scanf( " %d " , & n);
for ( int i = 0 ;i < n;i ++ )
{
printf( " 请输入第%d个数据元素的值:\n " ,i + 1 );
scanf( " %d " , & L -> data[i]);
}
L -> last = n - 1 ;
return L;
}
int cmp(seqlist * a,seqlist * b)
{
seqlist * na, * nb;
na = (seqlist * )malloc( sizeof (seqlist));
na -> last =- 1 ;
nb = (seqlist * )malloc( sizeof (seqlist));
nb -> last =- 1 ;
int i = 0 ;
while (i <= a -> last && i <= b -> last && a -> data[i] == b -> data[i])
i ++ ;
for ( int j = i;j <= a -> last;j ++ )
{
na -> data[j - i] = a -> data[j];
na -> last ++ ;
}
for ( int j = i;j <= b -> last;j ++ )
{
nb -> data[j - i] = b -> data[j];
nb -> last ++ ;
}
if (na -> last == nb -> last && na -> last ==- 1 )
return 0 ;
else
{
if (na -> last >- 1 && nb -> last ==- 1 || na -> last >- 1 && nb -> last >- 1 && na -> data[ 0 ] > nb -> data[ 0 ])
return 1 ;
else
return - 1 ;
}
}
int main()
{
int n;
seqlist * A, * B;
A = Creat_seqlist();
B = Creat_seqlist();
n = cmp(A,B);
if (n == 0 )
printf( " 线性表A==B\n " );
else
{
if (n == 1 )
printf( " 线性表A>B\n " );
else
printf( " 线性表A<B\n " );
}
system( " pause " );
return 0 ;
}
#include < stdlib.h >
#include < string .h >
#define MAXSIZE 100
typedef int DataType;
typedef struct
{
DataType data[MAXSIZE];
int last;
}seqlist;
seqlist * Creat_seqlist()
{
int n;
seqlist * L;
L = (seqlist * )malloc( sizeof (seqlist));
L -> last =- 1 ;
printf( " 请输入创建的线性表的数据元素的个数:\n " );
scanf( " %d " , & n);
for ( int i = 0 ;i < n;i ++ )
{
printf( " 请输入第%d个数据元素的值:\n " ,i + 1 );
scanf( " %d " , & L -> data[i]);
}
L -> last = n - 1 ;
return L;
}
int cmp(seqlist * a,seqlist * b)
{
seqlist * na, * nb;
na = (seqlist * )malloc( sizeof (seqlist));
na -> last =- 1 ;
nb = (seqlist * )malloc( sizeof (seqlist));
nb -> last =- 1 ;
int i = 0 ;
while (i <= a -> last && i <= b -> last && a -> data[i] == b -> data[i])
i ++ ;
for ( int j = i;j <= a -> last;j ++ )
{
na -> data[j - i] = a -> data[j];
na -> last ++ ;
}
for ( int j = i;j <= b -> last;j ++ )
{
nb -> data[j - i] = b -> data[j];
nb -> last ++ ;
}
if (na -> last == nb -> last && na -> last ==- 1 )
return 0 ;
else
{
if (na -> last >- 1 && nb -> last ==- 1 || na -> last >- 1 && nb -> last >- 1 && na -> data[ 0 ] > nb -> data[ 0 ])
return 1 ;
else
return - 1 ;
}
}
int main()
{
int n;
seqlist * A, * B;
A = Creat_seqlist();
B = Creat_seqlist();
n = cmp(A,B);
if (n == 0 )
printf( " 线性表A==B\n " );
else
{
if (n == 1 )
printf( " 线性表A>B\n " );
else
printf( " 线性表A<B\n " );
}
system( " pause " );
return 0 ;
}