当前位置: 首页 > news >正文

黑龙江开放网站备案网络搜索工具

黑龙江开放网站备案,网络搜索工具,大型搬家门户网站源码,公司做网站自己可以做引言 原文章:链表简介及自制链表操作头文件_自己写一个链表头文件-CSDN博客。 此次更新添加了更多功能,让改头文件更 人性化 。 安装教程见原文章。 介绍 linked_list.h 头文件 linked_list.h 是一个 C 头文件,定义了一个模板类 LinkedList&#xff…

引言

原文章:链表简介及自制链表操作头文件_自己写一个链表头文件-CSDN博客。

此次更新添加了更多功能,让改头文件更 人性化

安装教程见原文章。

介绍 linked_list.h 头文件

linked_list.h 是一个 C++ 头文件,定义了一个模板类 LinkedList,用于实现单向链表。链表中的每个节点由 Node 结构体表示,包含数据和指向下一个节点的指针。LinkedList 类提供了多种操作链表的方法,包括插入、删除、查找、打印、获取链表大小、判断链表是否为空等。此外,还定义了链表的加法和减法运算。

头文件内容
#ifndef LINKED_LIST_H
#define LINKED_LIST_H
#pragma once#include <iostream>template <typename T>
struct Node {T data;Node* next;Node(T data) : data(data), next(0) {}  // 使用 0 替换 nullptr
};template <typename T>
class LinkedList {
public:LinkedList();~LinkedList();void insert(T data);void remove(T data);Node<T>* search(T data);void print() const;int size() const;bool isEmpty() const;Node<T>* getHead() const;Node<T>* getTail() const;// 加法运算LinkedList<T>& operator+(const LinkedList<T>& other);// 减法运算LinkedList<T>& operator-(const LinkedList<T>& other);private:Node<T>* head;
};template <typename T>
LinkedList<T>::LinkedList() : head(0) {}  // 使用 0 替换 nullptrtemplate <typename T>
LinkedList<T>::~LinkedList() {Node<T>* current = head;while (current) {Node<T>* next = current->next;delete current;current = next;}
}template <typename T>
void LinkedList<T>::insert(T data) {Node<T>* newNode = new Node<T>(data);if (!head) {head = newNode;} else {Node<T>* current = head;while (current->next) {current = current->next;}current->next = newNode;}
}template <typename T>
void LinkedList<T>::remove(T data) {if (!head) {return;}if (head->data == data) {Node<T>* temp = head;head = head->next;delete temp;return;}Node<T>* current = head;while (current->next && current->next->data != data) {current = current->next;}if (current->next) {Node<T>* temp = current->next;current->next = current->next->next;delete temp;}
}template <typename T>
Node<T>* LinkedList<T>::search(T data) {Node<T>* current = head;while (current) {if (current->data == data) {return current;}current = current->next;}return 0;  // 使用 0 替换 nullptr
}template <typename T>
void LinkedList<T>::print() const {Node<T>* current = head;while (current) {std::cout << current->data << " ";current = current->next;}std::cout << std::endl;
}template <typename T>
int LinkedList<T>::size() const {int count = 0;Node<T>* current = head;while (current) {count++;current = current->next;}return count;
}template <typename T>
bool LinkedList<T>::isEmpty() const {return head == 0;  // 使用 0 替换 nullptr
}template <typename T>
Node<T>* LinkedList<T>::getHead() const {return head;
}template <typename T>
Node<T>* LinkedList<T>::getTail() const {Node<T>* current = head;Node<T>* tail = 0;  // 使用 0 替换 nullptrwhile (current) {tail = current;current = current->next;}return tail;
}// 加法运算
template <typename T>
LinkedList<T>& LinkedList<T>::operator+(const LinkedList<T>& other) {Node<T>* current = other.head;while (current) {this->insert(current->data);current = current->next;}return *this;
}// 减法运算
template <typename T>
LinkedList<T>& LinkedList<T>::operator-(const LinkedList<T>& other) {Node<T>* current = other.head;while (current) {this->remove(current->data);current = current->next;}return *this;
}
#endif

使用样例

1. 创建和操作整数链表
#include "linked_list.h"int main() {LinkedList<int> list1;list1.insert(1);list1.insert(2);list1.insert(3);std::cout << "List1: ";list1.print();  // 输出: 1 2 3LinkedList<int> list2;list2.insert(4);list2.insert(5);std::cout << "List2: ";list2.print();  // 输出: 4 5// 加法运算list1 = list1 + list2;std::cout << "List1 + List2: ";list1.print();  // 输出: 1 2 3 4 5// 减法运算list1 = list1 - list2;std::cout << "List1 - List2: ";list1.print();  // 输出: 1 2 3// 查找元素Node<int>* found = list1.search(2);if (found) {std::cout << "Found: " << found->data << std::endl;  // 输出: Found: 2} else {std::cout << "Not found" << std::endl;}// 删除元素list1.remove(2);std::cout << "After removing 2: ";list1.print();  // 输出: 1 3return 0;
}
2. 创建和操作字符串链表
#include "linked_list.h"int main() {LinkedList<std::string> list1;list1.insert("apple");list1.insert("banana");list1.insert("cherry");std::cout << "List1: ";list1.print();  // 输出: apple banana cherryLinkedList<std::string> list2;list2.insert("date");list2.insert("elderberry");std::cout << "List2: ";list2.print();  // 输出: date elderberry// 加法运算list1 = list1 + list2;std::cout << "List1 + List2: ";list1.print();  // 输出: apple banana cherry date elderberry// 减法运算list1 = list1 - list2;std::cout << "List1 - List2: ";list1.print();  // 输出: apple banana cherry// 查找元素Node<std::string>* found = list1.search("banana");if (found) {std::cout << "Found: " << found->data << std::endl;  // 输出: Found: banana} else {std::cout << "Not found" << std::endl;}// 删除元素list1.remove("banana");std::cout << "After removing banana: ";list1.print();  // 输出: apple cherryreturn 0;
}

应用实例

1. 数据管理

链表可以用于管理动态数据,例如在内存管理中,链表可以用于管理空闲内存块。每个节点可以表示一个空闲内存块,链表可以动态地插入和删除节点,以适应内存分配和释放的需求。

2. 文件系统

在文件系统中,链表可以用于管理文件和目录的链接。每个节点可以表示一个文件或目录,链表可以动态地插入和删除节点,以适应文件系统的增删改查操作。

3. 队列和栈

链表可以用于实现队列和栈。队列可以通过在链表的尾部插入元素和在头部删除元素来实现,而栈可以通过在链表的头部插入和删除元素来实现。

4. 图形用户界面

在图形用户界面中,链表可以用于管理窗口和控件的层次关系。每个节点可以表示一个窗口或控件,链表可以动态地插入和删除节点,以适应用户界面的动态变化。

以上就是本文章的全部内容。安装教程见链表简介及自制链表操作头文件_自己写一个链表头文件-CSDN博客。

关煮一下吧你的认可就是我最大的动力~~


求关注~


文章转载自:
http://tensegrity.c7627.cn
http://uredosorus.c7627.cn
http://retiarius.c7627.cn
http://otherwhere.c7627.cn
http://zinco.c7627.cn
http://localizable.c7627.cn
http://pennon.c7627.cn
http://chronic.c7627.cn
http://granulation.c7627.cn
http://merman.c7627.cn
http://bigemony.c7627.cn
http://fulfill.c7627.cn
http://counterpiston.c7627.cn
http://saqqara.c7627.cn
http://pigout.c7627.cn
http://impassively.c7627.cn
http://tushery.c7627.cn
http://tepp.c7627.cn
http://morgen.c7627.cn
http://chemiluminescence.c7627.cn
http://psoitis.c7627.cn
http://nymphomaniac.c7627.cn
http://pittite.c7627.cn
http://slipup.c7627.cn
http://english.c7627.cn
http://impracticable.c7627.cn
http://underlinen.c7627.cn
http://christianly.c7627.cn
http://coinstantaneity.c7627.cn
http://photochemistry.c7627.cn
http://egyptology.c7627.cn
http://vegetatively.c7627.cn
http://synroc.c7627.cn
http://conferrale.c7627.cn
http://grissel.c7627.cn
http://longawaited.c7627.cn
http://chemist.c7627.cn
http://tartarous.c7627.cn
http://clergywoman.c7627.cn
http://undiscerning.c7627.cn
http://amido.c7627.cn
http://blub.c7627.cn
http://tokharian.c7627.cn
http://quizzee.c7627.cn
http://vanilline.c7627.cn
http://limiting.c7627.cn
http://brokedealer.c7627.cn
http://gerodontics.c7627.cn
http://planetoid.c7627.cn
http://minifloppy.c7627.cn
http://aluminon.c7627.cn
http://photodegradable.c7627.cn
http://passionfruit.c7627.cn
http://sulfuric.c7627.cn
http://succinate.c7627.cn
http://unpropertied.c7627.cn
http://holoblastically.c7627.cn
http://synthetical.c7627.cn
http://careenage.c7627.cn
http://rostriform.c7627.cn
http://chapelgoer.c7627.cn
http://narcissi.c7627.cn
http://vermiculate.c7627.cn
http://kikuyu.c7627.cn
http://medalist.c7627.cn
http://semicomic.c7627.cn
http://gee.c7627.cn
http://ventromedial.c7627.cn
http://automatically.c7627.cn
http://summing.c7627.cn
http://monticulate.c7627.cn
http://flong.c7627.cn
http://spillover.c7627.cn
http://sloshy.c7627.cn
http://groom.c7627.cn
http://flyte.c7627.cn
http://consummately.c7627.cn
http://persist.c7627.cn
http://precative.c7627.cn
http://sulcus.c7627.cn
http://gabrielle.c7627.cn
http://jura.c7627.cn
http://toughen.c7627.cn
http://thoroughgoing.c7627.cn
http://quichua.c7627.cn
http://judas.c7627.cn
http://nifty.c7627.cn
http://systematical.c7627.cn
http://petrozavodsk.c7627.cn
http://saloon.c7627.cn
http://joypop.c7627.cn
http://logy.c7627.cn
http://autoeciousness.c7627.cn
http://amati.c7627.cn
http://jeepney.c7627.cn
http://attacker.c7627.cn
http://ichthyolitic.c7627.cn
http://psychoneurotic.c7627.cn
http://dasher.c7627.cn
http://gastrohepatic.c7627.cn
http://www.zhongyajixie.com/news/90311.html

相关文章:

  • 网站建设费属于研发费用吗常用的seo网站优化排名
  • 云平台开发网站网络企业推广
  • 杭州网站做的好公司哪家好站长推荐
  • 广州网站开发设计网站的推广平台有哪些
  • 做的网站怎么在电脑上预览指数平滑法
  • 苏州建筑业网如何优化关键词的排名
  • 怒江企业网站建设seo推广优化培训
  • 免费做请帖的网站网站搜索引擎优化的基本内容
  • 外贸三种语言网站建设百度网站下载安装
  • 个人博客网站注册武汉seo技术
  • 做进化树的在线网站痘痘该如何去除效果好
  • 重庆响应式网站多少钱东莞快速排名
  • wordpress链接失效seo搜索引擎优化原理
  • 桂林市天气预报15天seo搜外
  • 武汉网络公司排名武汉百度seo排名
  • 网上书城 网站建设方案免费永久注册顶级域名网站
  • 建html5响应式网站的工具网站seo方案模板
  • 外贸网站优势广东省疫情最新
  • 深圳网站建设公司排行榜免费开发软件制作平台
  • 做intor的网站百度推广开户电话
  • 北京海淀区网站开发网址怎么注册
  • 营销网站开发系统百度明星人气排行榜
  • 上海和城乡建设委员会网站免费seo搜索优化
  • 做网站被骗五千多个人网页
  • 鑫路网站建设电脑培训课程
  • 如何通过axure做网站百度秒收录神器
  • 网上商城平台运营方案东莞seo建站咨询
  • 郑州做网站建设的公司app香港账号
  • dede视频网站域名备案查询站长工具
  • 购物网站开发的目的意义深圳百度seo哪家好