Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
SmallBambooCode authored May 23, 2024
1 parent b914be9 commit 2318599
Show file tree
Hide file tree
Showing 16 changed files with 5,002 additions and 0 deletions.
926 changes: 926 additions & 0 deletions AML.h

Large diffs are not rendered by default.

247 changes: 247 additions & 0 deletions DLinkList.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,247 @@
#pragma once
#include <iostream>
#include <fstream>
#include <sstream>
using namespace std;

// 节点类
template<typename T>
class Node {
private:
T data;
Node<T>* pre;
Node<T>* next;
public:
// 构造析构
Node(Node<T>* next = nullptr, Node<T>* pre = nullptr) {
this->next = next;
this->pre = pre;
}
Node(const T& data, Node<T>* next = nullptr, Node<T>* pre = nullptr) {
this->data = data;
this->next = next;
this->pre = pre;
}

// 节点操作
Node<T>* getNext() {
return this->next;
}
Node<T>* getPre() {
return this->pre;
}
T getData() {
return this->data;
}
void setNext(Node<T>* next) {
this->next = next;
}
void setPre(Node<T>* pre) {
this->pre = pre;
}
void setData(const T& item) {
this->data = item;
}
// 运算符重载
bool operator==(Node<T>& obj) {
if (this->getData() == obj.getData()) {
return true;
}
else {
return false;
}
}
bool operator!=(Node<T>& obj) {
if (this->getData() == obj.getData()) {
return false;
}
else {
return true;
}
}
friend ostream& operator<< (ostream& out, Node<T>& t) {
out << t.getData();
return out;
}
friend istream& operator>> (istream& in, Node<T>& t) {
T temp;
cin >> temp;
t.setData(temp);
return in;
}
Node<T>& operator=(Node<T>& obj) {
this->setData(obj.data);
this->next = obj.next;
this->pre = obj.pre;
return *this;
}
};

// 双向链表类
template<typename T>
class DLinkList {
private:
Node<T>* head;
Node<T>* tail;
public:
// 构造析构
DLinkList() {
head = new Node<T>;
tail = new Node<T>;
head->setNext(tail);
tail->setPre(head);
}
DLinkList(const T& data) {
this->head = new Node<T>;
this->tail = new Node<T>;
this->head->setNext(new Node<T>(data));
tail->setPre(head->getNext());
}
DLinkList(const DLinkList<T>& list) {
// 创建头尾节点
head = new Node<T>;
tail = new Node<T>;
head->setNext(tail);
tail->setPre(head);

// 复制list中的所有节点
Node<T>* temp = list.head->getNext();
while (temp != list.tail) {
this->addNode(temp->getData());
temp = temp->getNext();
}
}

~DLinkList() {
this->clearList();
delete this->head;
delete this->tail;
this->head = nullptr;
this->tail = nullptr;
}
// 链表操作
Node<T>* getHead() {
return this->head;
}
Node<T>* getTail() {
return this->tail;
}
bool addNode(T data) {
Node<T>* newNode = new Node<T>(data);
Node<T>* temp = head;
while (temp->getNext() != tail) {
temp = temp->getNext();
}
temp->setNext(newNode);
newNode->setPre(temp);
newNode->setNext(tail);
tail->setPre(newNode);
return true;
}
void printList() {
Node<T>* temp = head;
while (temp->getNext() != tail) {
cout << temp->getNext()->getData() << endl;
temp = temp->getNext();
}
return;
}
void rprintList() {
Node<T>* temp = tail;
while (temp->getPre() != head) {
cout << temp->getPre()->getData() << endl;
temp = temp->getPre();
}
return;
}
bool deleteNode(T data) {
Node<T>* temp = tail;
while (temp->getPre() != head) {
if (temp->getPre()->getData() == data) {
Node<T>* toDelete = temp->getPre();
toDelete->getPre()->setNext(toDelete->getNext());
toDelete->getNext()->setPre(toDelete->getPre());
delete toDelete;
toDelete = nullptr;
return true;
}
temp = temp->getPre();
}
return false;
}
bool modifyNode(T from, T to) {
Node<T>* temp = tail;
while (temp->getPre() != head) {
if (temp->getPre()->getData() == from) {
temp->getPre()->setData(to);
return true;
}
temp = temp->getPre();
}
return false;
}
bool searchNode(T data) {
Node<T>* temp = tail;
while (temp->getPre() != head) {
if (temp->getPre()->getData() == data) {
return true;
}
temp = temp->getPre();
}
return false;
}
void clearList() {
Node<T>* toDelete = head->getNext();
// 遍历链表删除所有节点
while (toDelete != this->tail) {
Node<T>* nextNode = toDelete->getNext();
delete toDelete;
toDelete = nextNode;
}
this->head->setNext(this->tail);
this->tail->setPre(this->head);
}
// 运算符重载
bool operator==(DLinkList<T>& obj) {
if (this->head == obj.getHead() && this->tail == obj.tail) {
return true;
}
else {
return false;
}
}
bool operator!=(DLinkList<T>& obj) {
if (this->head == obj.getHead() && this->tail == obj.tail) {
return false;
}
else {
return true;
}
}
friend ostream& operator<< (ostream& out, DLinkList<T>& t) {
Node<T>* temp = t.getHead();
if (temp->getNext() == t.getTail()) {
return out;
}
while (temp->getNext() != t.getTail()) {
out << temp->getNext()->getData() << endl;
temp = temp->getNext();
}
return out;
}

DLinkList<T>& operator=(const DLinkList<T>& list) {
if (this != &list) {
// 先清空当前链表
this->clearList();

// 复制list中的所有节点
Node<T>* temp = list.head->getNext();
while (temp != list.tail) {
this->addNode(temp->getData());
temp = temp->getNext();
}
}
return *this;
}
};
112 changes: 112 additions & 0 deletions MyVector.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
#pragma once
#include <iostream>
using namespace std;

template <typename T>
class MyVector {
private:
// 指向动态分配的数组
T* base;
// 容器容量
int capacity;
// 当前元素数量
int current;

public:
// 构造函数,初始化为1容量的数组
MyVector() {
base = new T[1];
capacity = 1;
current = 0;
}
// 带参构造函数,用指定的初始值和容量初始化元素
MyVector(int initCapacity, const T& initValue) {
base = new T[initCapacity];
capacity = initCapacity;
current = initCapacity;
for (int i = 0; i < initCapacity; i++) {
base[i] = initValue;
}
}
// 拷贝构造函数
MyVector(const MyVector& other) {
capacity = other.capacity;
current = other.current;
base = new T[capacity];
for (int i = 0; i < current; i++) {
base[i] = other.base[i];
}
}
// 析构函数,清理动态分配的内存
~MyVector() {
delete[] base;
base = nullptr;
}
// 向容器尾部添加元素
void push_back(T data) {
if (current == capacity) {
T* temp = new T[2 * capacity];
for (int i = 0; i < capacity; i++) {
temp[i] = base[i];
}
delete[] base;
capacity *= 2;
base = temp;
}
base[current] = data;
current++;
}
// 移除容器尾部的元素
void pop_back() {
current--;
}
void erase(int index) {
if (index >= 0 && index < current) {
for (int i = index; i < current - 1; i++) {
base[i] = base[i + 1];
}
current--;
}
else {
return;
}
}
// 获取当前元素个数
int size() {
return current;
}
// 获取容量
int getcapacity() {
return capacity;
}
// 返回一个指向数组首元素的指针
T* begin() {
return base;
}
// 返回一个指向数组尾后元素的指针
T* end() {
return base + current;
}
// 判断容器是否为空
bool empty() {
return current == 0;
}
// 重载下标操作符,允许使用数组下标访问方式
T& operator[](int index) {
return base[index];
}
// 重载赋值运算符
MyVector& operator=(const MyVector& other) {
if (this != &other) {
delete[] base;

capacity = other.capacity;
current = other.current;
base = new T[capacity];
for (int i = 0; i < current; i++) {
base[i] = other.base[i];
}
}
return *this;
}
};
4 changes: 4 additions & 0 deletions PythonAI启动.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
@ECHO OFF
title BeijingSubwayAIAssistant by SmallBamboo
"D:\AnacondaEnvs\PyFlask\python.exe" D:\×ÀÃæ\±à³ÌÏà¹Ø\04_IDEÁ·Ï°ÏîÄ¿\Python\BeijingSubway\BeijingSubwayAIAssistant.py
exit
9 changes: 9 additions & 0 deletions Python后端启动.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
@ECHO OFF
:start
title 小竹VPS客户管理系统后端 by SmallBamboo
@echo.开始启动
"D:\AnacondaEnvs\PyFlask\python.exe" D:\桌面\编程相关\04_IDE练习项目\Python\BeijingSubway\app.py
@echo 服务器后端10秒后自动重启,如不需要重启,请直接关掉
choice /t 10 /d y /n >nul
goto start
pause
Loading

0 comments on commit 2318599

Please sign in to comment.