简单的c++程序补充,已经写得差不多了,只要再对其中的几个注释语句进行编写就可以了

[复制链接]
查看11 | 回复1 | 2009-6-23 18:48:25 | 显示全部楼层 |阅读模式
#include
#include
class SingleList;

class Node{
private:
int data;
Node*link;
friend class SingleList;
};
class SingleList{
public:

SingleList(){ first=NULL; n=0; }

~SingleList();
//
bool IsEmpty() const;
//
int Length() const;
//
bool Find(int i,int & x) const;//将链表的每i个结点的值通过x返回
//
int Search(intx) const;
//查找给定的x,返回是链表中的第几个结点,若不存在则返回0

bool Insert(int i,intx);
//在链表的每i个结点后插入值为x的结点
//
bool Delete(int i);
//删除链表的每i个结点
//
bool Update(int i,intx);
//对链表的每i个结点的值用x的值更新

void Output(ostream& out) const; //输出链表每一个结点的值

friend ostream& operatorlink;
delete q;
}
}
bool SingleList::Insert(int i,intx)
//在链表的每i个结点后插入值为x的结点
{
Node *p=first,*q;
q=new Node;
q->data=x;
q->link=NULL;
if(i>0){
while(--i)
p=p->link;
p->link=q;
}
else if(i==0)
first=q;
else
return false;
n++;
return true;
}
void SingleList::Output(ostream& out) const //输出链表每一个结点的值
{
Node *p=first;

for(int i=0;idatalink;
}
}
ostream& operator<<(ostream& out, const SingleList &t) //重载输出流调用Output函数,输出链表
{
t.Output(out);
return out;
}

回复

使用道具 举报

千问 | 2009-6-23 18:48:25 | 显示全部楼层
还差得多呢!!...
回复

使用道具 举报

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

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行