单链表按位查找的C程序

上传人:平*** 文档编号:16048366 上传时间:2017-11-06 格式:DOC 页数:4 大小:32.07KB
返回 下载 相关 举报
单链表按位查找的C程序_第1页
第1页 / 共4页
单链表按位查找的C程序_第2页
第2页 / 共4页
单链表按位查找的C程序_第3页
第3页 / 共4页
单链表按位查找的C程序_第4页
第4页 / 共4页
亲,该文档总共4页,全部预览完了,如果喜欢就下载吧!
资源描述

《单链表按位查找的C程序》由会员分享,可在线阅读,更多相关《单链表按位查找的C程序(4页珍藏版)》请在金锄头文库上搜索。

1、C+课程实训 建立线性单链表 要有初始化、插入、删除、查找、排序等常用功能的 C+程序,必须要有封装性!#include using namespace std; template class list;template class nodefriend list;private:T data;node* next;public:node():data(0),next(NULL);node()T getData()return data;node* getNext()return next;template class listprivate:node *head;public:list()h

2、ead=new node;list();int insert(T&);int remove(T&);node* find(T&);void print();void sort();template int list:insert(T& x)node *p=new node;p-data=x; if(!p) return 0;p-next=head-next;head-next=p;return 1;templateint list:remove(T& x)node* p=find(x);if(!p) return 0;node *q=p-next;p-next=q-next;delete q;

3、return 1;templatenode *list:find(T& x)node*q=head;while(q-next!=NULL)if(q-next-data=x)return q;q=q-next;return NULL;templatevoid list:sort()node* p=head-next,*q;for(;p!=NULL;p=p-next)for(q=p-next;q!=NULL;q=q-next)if(p-dataq-data)T temp=q-data;q-data=p-data;p-data=temp;templatevoid list:print()node *

4、q=head-next;while(q!=NULL)coutdata;q=q-next;coutlist:list()node*p=head-next;while(p!=NULL)head-next=p-next;delete p;p=head-next;delete head;int main() list l;int x;do cinx;/input 0 exitif(x=0) break;l.insert(x); while (1);l.sort();l.print();cinx;node* p=l.find(x)-getNext();coutgetData()endl;l.remove(x);l.print();return 0;

展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 办公文档 > 其它办公文档

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号