主题:[讨论]请教关于数据结构的顺序表问题!
这个程序的错误有点奇怪,大家指点指点!!
下面的程序出现这样的错误:c:\documents and settings\user\桌面\数据结构\seqlist\selecttm.h(75) : error C2679: binary '>>' : no operator defined which takes a right-hand operand of type 'const int' (or there is no acceptable conversion)
这是什么错误 啊????????????????/
#ifndef SEQLIST_H
#define SEQLIST_H
#include<iostream.h>
const int defaultSize=100;
const int PER_ADD_NUM=50;
template <class Type> class SeqList{
public:
SeqList(const int sz=defaultSize);
~SeqList(){delete[]data;}
int Length()const{return last+1;}
int Find(const Type&x)const;
int IsIn (Type&x);
int Insert(Type&x,int i);
int Remove(Type&x);
int Next(Type&x);
int Prior(Type&x);
int IsEmpty() const {return last==-1;}
int IsFull() const{return last==MaxSize-1;}
Type Get(int i){return i<0 || i>last? NULL:data[i];}
friend ostream &operator<<(ostream&outStream,const SeqList<Type>&outList);
friend istream &operator>>(istream&inStream,const SeqList<Type>&inList);
private:
Type *data;
int MaxSize;
int last;
int ArraySize;
};
#endif
#ifndef SELECTTM_H
#define SELECTTM_H
#include "seqlist.h"
template<class Type>SeqList<Type>::SeqList(int sz){
if(sz>0)
{
MaxSize=sz;
ArraySize=0;
last=ArraySize-1;
data=new Type[MaxSize];
}
}
template<class Type>int SeqList<Type>::Find(const Type&x)const{
int i=0;
while(i<=last&&data[i]!=x)i++;
if (i>last) {cout<<"查找失败"<<endl;return-1;}
else {cout<<"查找成功"<<endl;return i;}
}
template<class Type>int SeqList<Type>::IsIn(Type&x){
int i=0,found=0;
while (i<=last&&!found)
if(data[i]!=x)i++;
else found =1;
return found;
}
template<class Type>int SeqList<Type>::Insert(Type&x,int i){
if(i<0 || i>last+1) return 0;
else
{
if (last==MaxSize-1)
ReSize(MaxSize+PER_ADD_NUM);
last++;
for(int j=last;j>i;j--)data[j]=data[j-1];
data[i]=x;
return 1;
}
}
template<class Type>int SeqList<Type>::Remove(Type&x){
int i=Find(x);
if(i>=0)
{
last--;
for(int j=i;j<=MaxSize;j++)data[j]=data[j+1];
return 1;
}
return 0;
}
template<class Type>int SeqList<Type>::Next(Type&x ){
int i=Find(x);
if(i>=0&&i<last)return i+1;
else return -1;
}
template<class Type>int SeqList<Type>::Prior(Type&x ){
int i=Find(x);
if(i>=0&&i<=last)return i-1;
else return -1;
}
template<class Type> ostream&operator<<(ostream&OutStream,const SeqList<Type>&OutList){
OutStream<<"输出:\n";
for(int i=0;i<OutList.ArraySize;i++)
OutStream<<OutList.data[i]<<' ';
OutStream<<endl;
OutStream<<"数组:"<<OutList.ArraySize<<endl;
return OutStream;
}
template<class Type> istream&operator>>(istream&InStream,const SeqList<Type>&InList){
cout<<"输入数组个数:"<<endl;
InStream>>InList.ArraySize>>endl; //为什么这里有错误!!
cout<<"输入数组:\n";
for(int i=0;i<InList.ArraySize;i++){
cout<<"data"<<i<<":";
InStream>>InList.data[i];
}
return InStream;
}
#endif
#include"selecttm.h"
const int SIZE=20;
int main(){
SeqList<int>TestList(SIZE);
int x;
cin>>TestList;
cin>>x;
cout<<TestList;
TestList.Find(x);
return 0;
}
下面的程序出现这样的错误:c:\documents and settings\user\桌面\数据结构\seqlist\selecttm.h(75) : error C2679: binary '>>' : no operator defined which takes a right-hand operand of type 'const int' (or there is no acceptable conversion)
这是什么错误 啊????????????????/
#ifndef SEQLIST_H
#define SEQLIST_H
#include<iostream.h>
const int defaultSize=100;
const int PER_ADD_NUM=50;
template <class Type> class SeqList{
public:
SeqList(const int sz=defaultSize);
~SeqList(){delete[]data;}
int Length()const{return last+1;}
int Find(const Type&x)const;
int IsIn (Type&x);
int Insert(Type&x,int i);
int Remove(Type&x);
int Next(Type&x);
int Prior(Type&x);
int IsEmpty() const {return last==-1;}
int IsFull() const{return last==MaxSize-1;}
Type Get(int i){return i<0 || i>last? NULL:data[i];}
friend ostream &operator<<(ostream&outStream,const SeqList<Type>&outList);
friend istream &operator>>(istream&inStream,const SeqList<Type>&inList);
private:
Type *data;
int MaxSize;
int last;
int ArraySize;
};
#endif
#ifndef SELECTTM_H
#define SELECTTM_H
#include "seqlist.h"
template<class Type>SeqList<Type>::SeqList(int sz){
if(sz>0)
{
MaxSize=sz;
ArraySize=0;
last=ArraySize-1;
data=new Type[MaxSize];
}
}
template<class Type>int SeqList<Type>::Find(const Type&x)const{
int i=0;
while(i<=last&&data[i]!=x)i++;
if (i>last) {cout<<"查找失败"<<endl;return-1;}
else {cout<<"查找成功"<<endl;return i;}
}
template<class Type>int SeqList<Type>::IsIn(Type&x){
int i=0,found=0;
while (i<=last&&!found)
if(data[i]!=x)i++;
else found =1;
return found;
}
template<class Type>int SeqList<Type>::Insert(Type&x,int i){
if(i<0 || i>last+1) return 0;
else
{
if (last==MaxSize-1)
ReSize(MaxSize+PER_ADD_NUM);
last++;
for(int j=last;j>i;j--)data[j]=data[j-1];
data[i]=x;
return 1;
}
}
template<class Type>int SeqList<Type>::Remove(Type&x){
int i=Find(x);
if(i>=0)
{
last--;
for(int j=i;j<=MaxSize;j++)data[j]=data[j+1];
return 1;
}
return 0;
}
template<class Type>int SeqList<Type>::Next(Type&x ){
int i=Find(x);
if(i>=0&&i<last)return i+1;
else return -1;
}
template<class Type>int SeqList<Type>::Prior(Type&x ){
int i=Find(x);
if(i>=0&&i<=last)return i-1;
else return -1;
}
template<class Type> ostream&operator<<(ostream&OutStream,const SeqList<Type>&OutList){
OutStream<<"输出:\n";
for(int i=0;i<OutList.ArraySize;i++)
OutStream<<OutList.data[i]<<' ';
OutStream<<endl;
OutStream<<"数组:"<<OutList.ArraySize<<endl;
return OutStream;
}
template<class Type> istream&operator>>(istream&InStream,const SeqList<Type>&InList){
cout<<"输入数组个数:"<<endl;
InStream>>InList.ArraySize>>endl; //为什么这里有错误!!
cout<<"输入数组:\n";
for(int i=0;i<InList.ArraySize;i++){
cout<<"data"<<i<<":";
InStream>>InList.data[i];
}
return InStream;
}
#endif
#include"selecttm.h"
const int SIZE=20;
int main(){
SeqList<int>TestList(SIZE);
int x;
cin>>TestList;
cin>>x;
cout<<TestList;
TestList.Find(x);
return 0;
}