?? binary_search_singlelist.h
字號:
#include<iostream.h>
template<class type> class SetList;
template<class type> class SetNode
{
friend class SetList<type>;
public:
SetNode(const type& item):data(item),link(NULL){};
private:
type data;
char name,six,age;
SetNode<type> * link;
};
template<class type> class SetList
{
public:
SetList();
void MakeEmpty();
int AddMember(const type& x);
int DelMember(const type& x);
int Contains(const type& x);
Display();
~SetList();
//type &Min();
//type &Max();
private:
SetNode<type> * first, * last;
};
template<class type>SetList<type>::SetList()
{
first=last=new SetNode<type>(0);
}
template<class type> int SetList<type>::Contains(const type & x)
{
SetNode<type> * temp=first->link;
while(temp!=NULL&&temp->data<x)
temp=temp->link;
if(temp!=NULL&&temp->data==x)
return 1;
else
return 0;
}
template<class type> int SetList<type>::AddMember(const type& x)
{
SetNode<type> * p=first->link,* q=first;
while(p!=NULL&&p->data<x)
{
q=p;
p=p->link;
}
if(p!=NULL&&p->data==x)
return 0;
SetNode<type> * s=new SetNode<type>(x);
s->link=p;
q->link=s;
return 1;
}
template <class type> int SetList<type>::DelMember(const type& x)
{
SetNode<type> * p=first->link, * q=first;
while(p!=NULL&&p->data<x)
{
q=p;
p=p->link;
}
if(p!=NULL&&p->data==x)
{
q->link=p->link;
if(p==last)
last=q;
delete p;
return 1;
}
else
return 0;
}
template<class type> void SetList<type>::MakeEmpty()
{
SetNode<type> * del;
while(first->link!=NULL)
{ del=first->link;
first->link=first->link->link;
delete del;
};
last->link=first->link;
last=first;
cout<<"成功清空鏈表!";
}
template<class type> SetList<type>::~SetList()
{
SetNode<type> * del;
while(first!=0)
{ del=first;
first=first->link;
delete del;
};
cout<<"成功釋放鏈表空間!"<<'\n';
}
template<class type> SetList<type>::Display()
{
SetNode<type> * print;
print=first->link;
if(print==NULL)
cout<<endl<<"鏈表為空!";
else
{
cout<<endl<<"當前鏈表中所有結點 : ";
while(print!=NULL)
{
cout<<"->"<<print->data;
print=print->link;
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -