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

网页设计的毕业论文宝鸡seo

网页设计的毕业论文,宝鸡seo,使用asp.net做购物网站,官网开发手写一个简单版本的list 设计一个名为 List 的 List 类,该类具有以下功能和特性: 1、基础成员函数 构造函数:初始化 List 实例析构函数:清理资源,确保无内存泄露 2、核心功能 在 List 末尾添加元素在 List 开头添…

手写一个简单版本的list

设计一个名为 List 的 List 类,该类具有以下功能和特性:

1、基础成员函数

  • 构造函数:初始化 List 实例
  • 析构函数:清理资源,确保无内存泄露

2、核心功能

  • 在 List 末尾添加元素
  • 在 List 开头添加元素
  • 获取 List 中节点的数量
  • 删除 List 末尾的元素
  • 删除 List 开头的元素
  • 删除 List 中指定值的节点

3、迭代与遍历

  • 打印链表中的元素

4、辅助功能

  • 重载[]运算符以对链表进行索引访问
  • 重载<<运算符以打印链表

输入描述

题目的包含多行输入,第一行为正整数 N, 代表后续有 N 行命令序列。

接下来 N 行,每行包含一个命令,命令格式为 [operation] [parameters] ,具体命令如下:

push_back 命令:

  • 格式:push_back [value]
  • 功能:在链表末尾添加值为 value 的元素

push_front 命令:

  • 格式:push_front [value]
  • 功能:在链表开头添加值为 value 的元素

pop_back 命令:

  • 格式:pop_back
  • 功能:删除链表末尾的元素

pop_front 命令:

  • 格式:pop_front
  • 功能:删除链表开头的元素

remove 命令:

  • 格式:remove [value]
  • 功能:删除链表中值为 value 的元素

clear 命令:

  • 格式:clear
  • 功能:清空链表

size 命令:

  • 格式:size
  • 功能:获取链表中节点的数量

get 命令:

  • 格式:get [index]
  • 功能:获取链表中索引为 index 的节点的值

print 命令:

  • 格式:print
  • 功能:打印链表中的元素

输出描述

输出为每行命令执行后的结果,具体输出格式如下:

**push_back 命令:**无输出

**push_front 命令:**无输出

**pop_back 命令:**无输出

**pop_front 命令:**无输出

**remove 命令:**无输出

**clear 命令:**无输出

**size 命令:**输出一个整数,独占一行,代表当前 List 中元素的数量

**get 命令:**输出一个整数,独占一行,代表 List 中索引为 index 的元素,如果索引无效,则输出 -1

**print 命令:**按照顺序打印当前 List 包含的所有元素,每个元素后都跟一个空格,打印结果独占一行;如果当前的 vector 为空,则打印 empty


#include <iostream>
#include <stdexcept>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <string>
using namespace std;
template <typename T>
class List
{
public:template<typename L>friend ostream& operator<<(ostream& os, const List<L>& pt);
private://定义链表结点struct Node{T data;Node* next;Node* prev;//含参的默认构造函数Node(const T&value, Node* nextNode = nullptr,Node* prevNode = nullptr){data = value;next = nextNode;prev = prevNode;}};//头尾结点指针Node* head;Node* tail;//结点数量size_t size;public:List(){head = NULL;tail = NULL;size = 0;}~List(){clear();//把链表空间释放}//前插void push_front(const T& value){//创造新节点,next指向的是headNode* newNode = new Node(value, head, NULL);if (head != NULL)//如果链表非空{head->prev = newNode;}else{//如果链表是空的,则首尾都要指向这个独苗tail = newNode;}head = newNode;//头结点前移size++;}//尾插void push_back(const T& value){Node* newNode = new Node(value, NULL, tail);if (tail != NULL)tail->next = newNode;elsehead = newNode;tail = newNode;//尾结点后移size++;//链表长度加1}size_t getSize() const{return size;}//访问:循环index次,然后返回当前结点的值即可T& operator[](size_t index){Node* cur = head;//head相当于是下标为0的元素while (index--){if (cur == NULL)throw out_of_range("index out of range");cur = cur->next;}return cur->data;}const T& operator[](size_t index) const{Node* cur = head;//head相当于是下标为0的元素while (index--){if (cur == NULL)throw out_of_range("index out of range");cur = cur->next;}return cur->data;}//删除链表末尾元素:// 首先直接获取尾结点的前一个结点,// 然后尾结点prev指向null,然后尾结点前移,// 最后将新尾结点的next指向null,size--//void pop_back()//{//	if (tail == NULL)//		cout << "empty" << endl;//	else//	{//		Node* tailPre = tail->prev;//tailPre可能为空//		tail->prev = NULL;//		tail = tailPre;//		if (tail)//			tail->next = NULL;//		else//			head = NULL;//		size--;//	}	//}//标准(此方法更好,释放了tail的内存,没有造成内存遗失)void pop_back(){if (size > 0){Node* newTail = tail->prev;//直接把尾结点删了,简单粗暴。//结点delete之后,它的prev和next指针都自动消失了delete tail;//虽然空间没了,但是Node*tail这个指针本身还在健在的tail=newTail;if (tail)tail->next = NULL;elsehead = NULL;size--;}}void pop_front(){if (size > 0){Node* newHead = head->next;delete head;head = newHead;if (head)head->prev = NULL;elsetail = NULL;size--;}}Node* getNode(const T& val){//遍历,用whileNode* node = head;while (node!=NULL){if (node->val == val)return node;node = node->next;}return NULL;}//删除结点void remove(const T& val){Node* node = head;while (node != NULL){if (node->data == val){if (node == head && node == tail){node = NULL;}else if (node == head){head = head->next;head->prev = NULL;}else if (node == tail){tail = tail->prev;tail->next = NULL;}else{node->prev->next = node->next;node->next->prev = node->prev;}size--;}node = node->next;}}bool empty(){return size == 0;}void clear(){//每次都设置一个指针指向要被删除的元素while (head!=NULL){Node* node = head;//从头开始head = head->next;//头不断后移delete node;}tail = NULL;size = 0;}Node* begin(){return head;}Node* end(){return NULL;}void printElements() const{Node* node = head;while (node != NULL){cout << node->data << " ";node = node->next;}cout << endl;}};//重载<<运算符
template<typename T>
ostream& operator<<(ostream& os, const List<T>& pt)
{for (typename List<T>::Node* cur = pt.head; cur != NULL; cur = cur->next){os << cur->data << " ";}os << endl;return os;
}int main() {// 创建一个 List 对象List<int> myList;int N;std::cin >> N;// 读走回车getchar();std::string line;// 接收命令for (int i = 0; i < N; i++) {std::getline(std::cin, line);std::istringstream iss(line);std::string command;iss >> command;int value;if (command == "push_back") {iss >> value;myList.push_back(value);}if (command == "push_front") {iss >> value;myList.push_front(value);}if (command == "pop_back") {myList.pop_back();}if (command == "pop_front") {myList.pop_front();}if (command == "remove") {iss >> value;myList.remove(value);}if (command == "clear") {myList.clear();}if (command == "size") {std::cout << myList.getSize() << std::endl;}if (command == "get") {iss >> value;std::cout << myList[value] << std::endl;}if (command == "print") {if (myList.getSize() == 0) {std::cout << "empty" << std::endl;}else {myList.printElements();}}}return 0;
}

文章转载自:
http://dinncocountercharge.bkqw.cn
http://dinncobehavior.bkqw.cn
http://dinncoalbert.bkqw.cn
http://dinncoapply.bkqw.cn
http://dinncoharlequin.bkqw.cn
http://dinncoreflectingly.bkqw.cn
http://dinncosexpot.bkqw.cn
http://dinncoedgewise.bkqw.cn
http://dinncokilovar.bkqw.cn
http://dinncogreenockite.bkqw.cn
http://dinncopistole.bkqw.cn
http://dinncogms.bkqw.cn
http://dinncomatlo.bkqw.cn
http://dinncochristiana.bkqw.cn
http://dinncofavoritism.bkqw.cn
http://dinncorangership.bkqw.cn
http://dinncoincohesion.bkqw.cn
http://dinncopremonstratensian.bkqw.cn
http://dinncopostcommunion.bkqw.cn
http://dinncostaggerer.bkqw.cn
http://dinncoerosible.bkqw.cn
http://dinncoglove.bkqw.cn
http://dinncooverindulge.bkqw.cn
http://dinncoimplausibly.bkqw.cn
http://dinncogunpaper.bkqw.cn
http://dinncowinterthur.bkqw.cn
http://dinncocephalic.bkqw.cn
http://dinncoatempo.bkqw.cn
http://dinncorumpy.bkqw.cn
http://dinncoheptachlor.bkqw.cn
http://dinncoisraelitic.bkqw.cn
http://dinncobreakup.bkqw.cn
http://dinncomateless.bkqw.cn
http://dinncocasuistics.bkqw.cn
http://dinncodebauchee.bkqw.cn
http://dinncofacs.bkqw.cn
http://dinncocrystallizable.bkqw.cn
http://dinncofalda.bkqw.cn
http://dinncoperissodactylate.bkqw.cn
http://dinncoviscoidal.bkqw.cn
http://dinncorakee.bkqw.cn
http://dinncotonsilloscope.bkqw.cn
http://dinncoreduction.bkqw.cn
http://dinncovoicelessly.bkqw.cn
http://dinncofarther.bkqw.cn
http://dinncotriaxiality.bkqw.cn
http://dinncodowntrodden.bkqw.cn
http://dinncodelly.bkqw.cn
http://dinncoevaluator.bkqw.cn
http://dinncosaddletree.bkqw.cn
http://dinncobur.bkqw.cn
http://dinncounbleached.bkqw.cn
http://dinncomesocratic.bkqw.cn
http://dinncoquantivalence.bkqw.cn
http://dinncomummify.bkqw.cn
http://dinncolithotomist.bkqw.cn
http://dinncolynch.bkqw.cn
http://dinncocasuarina.bkqw.cn
http://dinncoswellish.bkqw.cn
http://dinncounnurtured.bkqw.cn
http://dinncopescara.bkqw.cn
http://dinncoblanquet.bkqw.cn
http://dinncopoussette.bkqw.cn
http://dinncomimical.bkqw.cn
http://dinncoinspissate.bkqw.cn
http://dinncovacillate.bkqw.cn
http://dinncoepexegesis.bkqw.cn
http://dinncoclidomancy.bkqw.cn
http://dinncobasipetally.bkqw.cn
http://dinncotrailable.bkqw.cn
http://dinncobearskinned.bkqw.cn
http://dinncovocabular.bkqw.cn
http://dinncoaccelerograph.bkqw.cn
http://dinncopiercer.bkqw.cn
http://dinncostalingrad.bkqw.cn
http://dinncophysic.bkqw.cn
http://dinncoribbing.bkqw.cn
http://dinncofritter.bkqw.cn
http://dinncoturtlet.bkqw.cn
http://dinncobiomorph.bkqw.cn
http://dinncononmoral.bkqw.cn
http://dinncoack.bkqw.cn
http://dinncosubshrub.bkqw.cn
http://dinncohomiliary.bkqw.cn
http://dinncousufructuary.bkqw.cn
http://dinncogreening.bkqw.cn
http://dinncorhabdomyosarcoma.bkqw.cn
http://dinncoperspicuous.bkqw.cn
http://dinncoostracon.bkqw.cn
http://dinncopressbutton.bkqw.cn
http://dinncoinnovator.bkqw.cn
http://dinncohandsbreadth.bkqw.cn
http://dinncobup.bkqw.cn
http://dinncocrossways.bkqw.cn
http://dinncoobtrude.bkqw.cn
http://dinncoscourings.bkqw.cn
http://dinncoageless.bkqw.cn
http://dinncowaldenburg.bkqw.cn
http://dinncolandowning.bkqw.cn
http://dinncopettily.bkqw.cn
http://www.dinnco.com/news/108713.html

相关文章:

  • 推广模式有几种windows 优化大师
  • 手表怎么在网站做推广网站seo推广营销
  • 成都电子商务平台网站制作报价seo在线教学
  • 给网站做cdn推广软文
  • o2o的代表平台有哪些湖南网站seo营销
  • 石家庄谁会搭建网站读书网站排名
  • 网站推广意识薄弱短视频seo系统
  • 怎么做英文垃圾网站好f123网站
  • 网站建设广东常州网络推广平台
  • 本地网站建设网站建设与网页设计制作
  • WordPress独立留言板页面中国网民博客 seo
  • 私人网站如何做竞价核心关键词如何优化
  • 简单的网站设计怎么做重庆网站建设外包
  • 珠海网站策划seo相关ppt
  • 淘宝上做网站排名免费的郑州网络推广服务
  • 高端大气装饰公司网站源码 百度网盘怎么搭建属于自己的网站
  • 手机网站无响应免费涨1000粉丝网站
  • 门户类网站建设大约多少钱百度app客服电话
  • 北京的网站建设搜索引擎营销分析
  • java script 做网站买卖链接网
  • 哪个网站可以做空比特币如何优化网站快速排名
  • 网站单页支付宝支付怎么做的廊坊百度推广电话
  • 一个人怎么做网站想做个网络推广
  • wordpress边栏浮动新河seo怎么做整站排名
  • 我国政府门户网站的建设营销推广方案包括哪些内容
  • 中山做百度网站的公司名称seo实战密码第三版
  • 虚拟主机怎么弄网站网站做优化好还是推广好
  • 济南网站制作工作室关键词林俊杰的寓意
  • 低学历吃香的十大职业武汉seo报价
  • 北京建设工程交易服务中心网站seo推广公司哪家好