链表的基本使用
来源:互联网 发布:淘宝审核部门电话 编辑:程序博客网 时间:2024/05/22 13:16
链表的基本使用
创建链表,添加元素,删除元素
#include "iostream"using namespace std;struct node{ int data; node *next;};class list{ node *head;public: list() { head=NULL; } void insertlist(int a,int b); void deletelist(int a); void outputlist(); node* gethead() { return head; }};void list::outputlist(){ node *p=head; while (p!=NULL) { cout<<p->data<<" "; p=p->next; }}void list::insertlist(int a,int b){ node *q,*p,*s; s=new(node); s->data=b; p=head; if (head==NULL) { head=s; s->next=NULL; } else if (p->data==a) { s->next=p; head=s; } else { while (p->data!=a && p->next!=NULL) { q=p; p=p->next; } if (p->data==a) { q->next=s; s->next=p; } else { p->next=s; s->next=NULL; } }}void list::deletelist(int a){ node *p,*q; p=head; if (p==NULL) return ; if (p->data==a) { head=head->next; delete p; } else { while (p->data!=a && p->next!=NULL) { q=p; p=p->next; } if (p->data==a) { q->next=p->next; delete p; } }}int main(){ list A,B; int x,n; cout<<"输入将要插入链表A的数字个数:"; cin>>n; cout<<"输入"<<n<<"个数字:"; while (n--) { cin>>x; A.insertlist(0,x); } cout<<"链表A:"; A.outputlist(); cout<<"\n输入要删除的数字:"; cin>>x; A.deletelist(x); cout<<"链表A:"; A.outputlist(); return 0;}
0 0
- 链表的基本使用
- 链表的基本使用
- 使用链表的基本操作
- 双向链表的基本api使用
- MySql的基本使用,数据库,表,数据的基本操作
- 链表的基本使用一(构建链表)
- C/C++基本数据结构:链表的基本使用和实现
- 使用C++实现链表的基本操作
- Java 链表的基本结构与使用
- c#中内置链表的基本使用
- c#中内置链表的基本使用
- 数据库和表的基本使用
- mysql 临时表的基本使用
- Ant 的基本使用
- Ant 的基本使用
- Eclipse的基本使用
- Eclipse的基本使用
- JBuilder的基本使用
- 鸟哥的linux私房菜学习笔记十一 ,命令权限
- 如何清晰地思考:近一年来业余阅读的关于思维方面的知识结构整理(附大幅思维导图)
- 6. CSS 属性选择器
- k最近邻算法(KNN)的简介和python实现
- 在windows下安装linux操作系统
- 链表的基本使用
- POJ 3984 迷宫问题【迷宫最短路径 bfs】
- reGeorg+proxychains-ng组合试用
- 内核模式下 信号灯
- DesignPattern之Bridge
- java学习总结及心得体会
- 设计模式 装饰模式
- 机器学习之正则化
- 奈氏准则和香农公式