找回密码
 注册
搜索
热搜: 回贴
  • 前程无忧官网首页 有什么好的平台可以
  • 最新的销售平台 互联网营销的平台有哪
  • 制作网页的基本流程 网页制作和网页设
  • 【帝国CMS】输出带序号的列表(数字排
  • 网站建设公司 三一,中联,极东泵车的
  • 织梦 建站 织梦网站模版后台怎么更改
  • 云服务官网 哪些网站有免费的简历模板
  • 如何建网站要什么条件 建网站要用什么
  • 吉林市移动公司电话 吉林省退休人员网
  • 设计类毕业论文 网站设计与实现毕业论
查看: 1701|回复: 4

C++问题难坏我这个菜鸟了

[复制链接]
发表于 2009-11-5 00:48:39 | 显示全部楼层 |阅读模式 IP:江苏扬州
#include<iostream.h>
const int defaultSize=10;
template<class Type> class SeqList{
public:
SeqList(int MaxSize = defaultSize);
~SeqList(){ delete [] data;}
int Length() const {return last + 1;}
int Find(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(){ return last == -1;}
int IsFull(){ return last == MaxSize-1;}
Type Get(int i){ return i<0 || i>last? NULl :data[i];}
private:
Type * data;
int MaxSize;
int last;
};
template< class Type>
SeqList<Type>::SeqList(int sz){
if(sz > 0){
MaxSize=sz;
last = -1;
data = new Type[MaxSize];
}
}
template< class Type>
int SeqList<Type>::Find (Type & x)const{ //定位
int i=0;
while(i<= last && data[i] != x) i++; //顺序查找
if( i>last ) return -1;
else return i;
}
template< class Type>
int SeqList<Type>::IsIn (Type & x){ //判断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){ //插入x在表中第i个位置处
if(i<0 || i>last+1 || last == MasSize-1)return 0;
else {
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){ //删除x
int i = Find(x); //在表中查找x
if(i>=0){
last--;
for(int j=i;j<=last;j++)data[j] = data[j+1];
return 1;
}
return 0; //x在表中不存在,不能删除
}
template<class Type>
int SeqList<Type>::Next (Type & x){
int i=Find(x);
if(i>=0 && i<last)return i+1; //x的后继存在
else return -1; //x不在表中或是x的后继不存在
}
template<class Type>
int SeqList<Type>::Prior (Type & x){ //寻找x 的前驱
int i=Find(x);
if(i>0 && i<=last)return i-1; //x的前驱位置
else return -1;
}
void main()
{
SeqList<int> myS;
cout<<myS.Insert(11, 0); //??????????????????????????????????????????????????
cout<<myS.Length ()<<endl;

}
高手给看一下,Compiling不通过啊
发表于 2009-11-5 00:48:41 | 显示全部楼层 IP:江苏扬州
汗一个先。。。
定义的是Insert (Type & x, int i)好不好。。。
{
int i = 11;
cout<<myS.Insert(i, 0);
}
回复

使用道具 举报

发表于 2009-11-5 00:48:42 | 显示全部楼层 IP:江苏扬州
Insert (Type & x, int i);
能给解释一下这种定义吗?不太懂~~~~~(Type & x;)
回复

使用道具 举报

发表于 2009-11-5 00:48:43 | 显示全部楼层 IP:江苏扬州
以下是引用wenzenglin在2007-4-1 11:21:52的发言:
Insert (Type & x, int i);
能给解释一下这种定义吗?不太懂~~~~~(Type & x;)
这不是典型的引用调用么?
还是你是说Type?那个是模板。。
回复

使用道具 举报

发表于 2009-11-5 00:48:45 | 显示全部楼层 IP:江苏扬州
他是说把&去掉,因为没有这种格式:int &x=11;这是错误的.
insert不会修改这个参数,也不需要用引用.
还有,MasSize写错了,改MaxSize;
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|小黑屋|最新主题|手机版|微赢网络技术论坛 ( 苏ICP备08020429号 )

GMT+8, 2024-10-1 09:39 , Processed in 0.236530 second(s), 13 queries , Gzip On, MemCache On.

Powered by Discuz! X3.5

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表