改完了虽然能够运行,但是我把基类的一个保护成员改成了公有成员,遗憾!!!
#include
template
template
friend class dataList
public:
Node(){}
Type getKey()const{return key;}
void setKey(Type k){key=k;}
private:
Type key;
};
template
public:
dataList(int sz=10):ArraySize(sz)
{
Element=new Node
}
virtual ~dataList(){delete[] Element;}
void setCurrent(int lhs){CurrentSize=lhs}
Node
protected:
int ArraySize;
public:
int CurrentSize;
};
template
public:
orderedList(int sz=10):dataList
virtual ~orderedList(){}
friend ostream& operator<<(ostream& OutStream,const orderedList
friend istream& operator>>(istream& InStream,orderedList
void Order(Node
int Search(const Type &x)const;
};
template
{
if(i!=0&&a[i].getKey()Type p=a[i].getKey();
a[i]=a[i-1];
a[i-1].setKey(a[i].getKey());
Order(a,i-1);
}
template
{
int h=CurrentSize-1,l=0,mid;
while(l<=h)
{
mid=(l+h)/2;
if(Element[mid].getKey()
else if(Element[mid].getKey()>x)
h=mid-1;
else return mid+1;
}
return -1;
}
template
{
OutStream<<"Array Contents:\n";
for(int i=0;i
}
template
{
int x;
cout<<"Enter array Current Size:";
InStream>>InList.CurrentSize;
cout<<"Enter array elements:\n";
for(int i=0;i
InStream>>x;
InList.Element[i].setKey(x);
InList.Order(InList.Element,i);
}
return InStream;
}
int main()
{
int i=0,k=0,j=0;
cout<<"Please input the length of the array£º\t";
cin>>k;
orderedList
cin>>A;
cout<cout<<"1¡¢Search 2¡¢Quit\t";
cin>>j;
while(j==1)
{
cout<<"Please input the number you search for£º\t";
cin>>i;
if(A.Search(i)==-1)
cout<<"Not found£¡\n";
else
cout<<"The location of the number is"<
cin>>j;
}
return 0;
}
可以运行。。
#include
template
template
friend class dataList
public:
Node(){}
Type getKey()const{return key;}
void setKey(Type k){key=k;}
private:
Type key;
};
template
public:
dataList(int sz=10):ArraySize(sz)
{
Element=new Node
}
virtual ~dataList(){delete[] Element;}
void setCurrent(int lhs){CurrentSize=lhs}
Node
protected:
int ArraySize;
public:
int CurrentSize;
};
template
public:
orderedList(int sz=10):dataList
virtual ~orderedList(){}
friend ostream& operator<<(ostream& OutStream,const orderedList
friend istream& operator>>(istream& InStream,orderedList
void Order(Node
int Search(const Type &x)const;
};
template
{
if(i!=0&&a[i].getKey()Type p=a[i].getKey();
a[i]=a[i-1];
a[i-1].setKey(a[i].getKey());
Order(a,i-1);
}
template
{
int h=CurrentSize-1,l=0,mid;
while(l<=h)
{
mid=(l+h)/2;
if(Element[mid].getKey()
else if(Element[mid].getKey()>x)
h=mid-1;
else return mid+1;
}
return -1;
}
template
{
OutStream<<"Array Contents:\n";
for(int i=0;i
}
template
{
int x;
cout<<"Enter array Current Size:";
InStream>>InList.CurrentSize;
cout<<"Enter array elements:\n";
for(int i=0;i
InStream>>x;
InList.Element[i].setKey(x);
InList.Order(InList.Element,i);
}
return InStream;
}
int main()
{
int i=0,k=0,j=0;
cout<<"Please input the length of the array£º\t";
cin>>k;
orderedList
cin>>A;
cout<cout<<"1¡¢Search 2¡¢Quit\t";
cin>>j;
while(j==1)
{
cout<<"Please input the number you search for£º\t";
cin>>i;
if(A.Search(i)==-1)
cout<<"Not found£¡\n";
else
cout<<"The location of the number is"<
cin>>j;
}
return 0;
}