首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C语言 >

数据结构的

2012-10-13 
求助数据结构的char Compare(SqList A, SqList B)// 比较顺序表A和B,//返回, 若AB//, 若AB//

求助数据结构的
char Compare(SqList A, SqList B)
// 比较顺序表A和B, 
// 返回'<', 若A<B;
// '=', 若A=B;
// '>', 若A>B
{
  int i = 0;
  int j = 0;
   
  while(A.elem[i]==B.elem[j]&&(!A.length==0)&&(!B.length==0)) {
  i++;
  j++;
  }
  if((A.length-i)==0&&(!B.length-j==0)) return '<';
  else if((!A.length-i==0)&&(B.length-j)==0) return '>';
  else if((A.length-i==0)&&(B.length-j==0)) return '=';
  else if((!A.length-i==0)&&(!B.length-j==0)){
  if(A.elem[i]>B.elem[j]) return '>';
  else return '<'; 
  }  
}请问哪里有错啊?

[解决办法]
你的while循环的终止条件是啥?如果不巧两块内存中的数据完全相同,你的 i、j会自增到什么地方去呢?
后面的没仔细看,但是 length - i 是什么东东?啥意思?

[解决办法]
while(A.elem[i]==B.elem[j]&&(!A.length==0)&&(!B.length==0))
{
i++;
j++;
}
1:弱弱的问一句你这个加入A 与B完全相同,什么时候结束??
应该改为:A.length-i != 0 && B.length - j != 0 是吧?? 
2:最后那个else if 应该改为else ,其他的情况你已经考虑了,这是最后一种?是吧??不然的话会出现:
warning C4715: 'Compare' : not all control paths return a value

[解决办法]
应该是While ()中的条件不对,后面的逻辑应该是没有错的。你把条件改为while(A.elem[i]==B.elem[j]&&(!(A.length-i)==0)&&(!(B.length-j)==0))试试

热点排行