[150420][C++]数据结构复习——链表实现源码
来源:互联网 发布:正确看待网络新一代 编辑:程序博客网 时间:2024/06/09 14:18
#include <iostream>#include <string>#include <cstdlib>using namespace std;class List{private:struct ListNode{string value;ListNode* next;}*head;public:List(){head = new(ListNode);head->next = NULL;}int Add(string value){ListNode* p = new(ListNode);p->value = value;ListNode* h = head;for (h = head; h->next != NULL; h = h->next);p->next = h->next;h->next = p;return 1;}int Add(int pos, string value){ListNode* p = new(ListNode);p->value = value;ListNode* h = head;for (int count = 1; count < pos; count++){if (h->next != NULL)h = h->next;elsereturn 0;}p->next = h->next;h->next = p;return 1;}int Delete(int pos){ListNode* p = new(ListNode);ListNode* h = head;for (int count = 1; count < pos; count++){if (h->next != NULL)h = h->next;elsereturn 0;}p = h->next;h->next = p->next;delete(p);return 1;}int Search(string value){ListNode* h;int count = 1;for (h = head; h->next != NULL; h = h->next){if (h->next->value == value)return count;elsecount++;}return 0;}void Print(){ListNode* h = head;for (h = head; h->next != NULL; h = h->next){cout << h->next->value << endl;}}};int main(){List l;l.Add(1,"A");l.Add(2,"B");l.Add(3,"C");l.Add("D");l.Delete(2);cout << l.Search("A") << endl;l.Print();system("pause");return 0;}
0 0
- [150420][C++]数据结构复习——链表实现源码
- [150421][C++]数据结构复习——栈实现源码
- [150422][C++]数据结构复习——队列实现源码
- 数据结构复习—C++实现简单链表
- 数据结构——复习C语言
- 数据结构—链表的复习
- 数据结构复习——线性表的顺序存储实现
- 数据结构复习—C++实现静态顺序表
- 复习(数据结构):线性表 : C
- 数据结构复习——线性表的链式存储实现(单向链表)
- 数据结构复习——线性表的链式存储实现(双向链表)
- 【数据结构链表复习】
- 数据结构复习—栈
- 数据结构复习—队列
- 数据结构复习1——链表反转
- 复习数据结构——线性表
- 数据结构复习——线性表概念
- 数据结构知识点复习——线性表
- 反渗透设备:反渗透设备在运行准备
- 解决 vs2010问题 error MSB8008: 指定的平台工具集(v110)未安装或无效
- iOS支付宝支付步骤
- win7绑定host
- sql System.Data.SqlClient.SqlError: 无法覆盖文件 'C:\Program Files\Microsoft SQL Server\MSSQL\data\itsm_Da
- [150420][C++]数据结构复习——链表实现源码
- Java网络编程从入门到精通(25):创建ServerSocket对象
- 创建3D模型/添加屏幕监听,点击屏幕时,精灵带有旋转的移动
- C中的volatile用法
- 反渗透设备:反渗透设备应用范围
- 海量数据面试题----分而治之/hash映射 + hash统计 + 堆/快速/归并排序
- 3.12
- 二叉树的镜像
- Android中的多选列表项对话框的一个细节问题