单链表按位查找的c程序

单链表按位查找的c程序

ID:9002759

大小:31.00 KB

页数:4页

时间:2018-04-14

单链表按位查找的c程序_第1页
单链表按位查找的c程序_第2页
单链表按位查找的c程序_第3页
单链表按位查找的c程序_第4页
资源描述:

《单链表按位查找的c程序》由会员上传分享,免费在线阅读,更多相关内容在应用文档-天天文库

1、C++课程实训建立线性单链表要有初始化、插入、删除、查找、排序等常用功能的C++程序,必须要有封装性!#includeusingnamespacestd;templateclasslist;templateclassnode{friendlist;private:Tdata;node*next;public:node():data(0),next(NULL){};~node(){}TgetData(){returndata;}node*ge

2、tNext(){returnnext;}};templateclasslist{private:node*head;public:list(){head=newnode;}~list();intinsert(T&);intremove(T&);node*find(T&);voidprint();voidsort();};templateintlist::insert(T&x){node*p=newnode;p->data=x;if(!p)return0;

3、p->next=head->next;head->next=p;return1;}templateintlist::remove(T&x){node*p=find(x);if(!p)return0;node*q=p->next;p->next=q->next;deleteq;return1;}templatenode*list::find(T&x){node*q=head;while(q->next!=NULL){if(q->next->data==x)

4、returnq;q=q->next;}returnNULL;}templatevoidlist::sort(){node*p=head->next,*q;for(;p!=NULL;p=p->next)for(q=p->next;q!=NULL;q=q->next)if(p->data>q->data){Ttemp=q->data;q->data=p->data;p->data=temp;}}templatevoidlist::print(){node*q=head-

5、>next;while(q!=NULL){cout<data;q=q->next;}cout<list::~list(){node*p=head->next;while(p!=NULL){head->next=p->next;deletep;p=head->next;}deletehead;}intmain(){listl;intx;do{cin>>x;//input0exitif(x==0)break;l.insert(x);}while(1)

6、;l.sort();l.print();cin>>x;node*p=l.find(x)->getNext();cout<getData()<

当前文档最多预览五页,下载文档查看全文

此文档下载收益归作者所有

当前文档最多预览五页,下载文档查看全文
温馨提示:
1. 部分包含数学公式或PPT动画的文件,查看预览时可能会显示错乱或异常,文件下载后无此问题,请放心下载。
2. 本文档由用户上传,版权归属用户,天天文库负责整理代发布。如果您对本文档版权有争议请及时联系客服。
3. 下载前请仔细阅读文档内容,确认文档内容符合您的需求后进行下载,若出现内容与标题不符可向本站投诉处理。
4. 下载文档时可能由于网络波动等原因无法下载或下载错误,付费完成后未能成功下载的用户请联系客服处理。