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

大型建筑网站设计公司详情中国做网站的公司排名

大型建筑网站设计公司详情,中国做网站的公司排名,轻松网站建设,重庆工程项目理论 链表的增删操作时间复杂度O(1),查询时间复杂度O(n),因为要从头结点开始。使用场景和数据完全相反 链表的储存地址是不连续的。也和数组不同。 移除链表元素 利用虚拟头结点可以同意操作。不然删除头结点需要额外写。 记得返回的是虚拟头结点的next而不是虚拟头结点retu…

理论

链表的增删操作时间复杂度O(1),查询时间复杂度O(n),因为要从头结点开始。使用场景和数据完全相反
链表的储存地址是不连续的。也和数组不同。

移除链表元素

利用虚拟头结点可以同意操作。不然删除头结点需要额外写。
记得返回的是虚拟头结点的next而不是虚拟头结点return dummyhead。哈哈哈

class Solution {
public:ListNode* removeElements(ListNode* head, int val) {ListNode* dummyhead = new ListNode(60);dummyhead->next=head;ListNode* cur=dummyhead;while(cur->next!=NULL){if(cur->next->val == val){ListNode* temp=cur->next;cur->next = cur->next->next;delete temp;}else{cur=cur->next;}}return dummyhead->next;}
};

设计链表

总是忘记判定插入或者删除的位置是否有效。

class MyLinkedList {
public:struct ListNode {int val;ListNode *next;ListNode(int val) : val(val), next(nullptr) {}};MyLinkedList() {dummyhead=new ListNode(0);size=0;}int get(int index) {if(index>size-1)return -1;ListNode* cur=dummyhead->next;for(int i=0;i<index;i++){cur=cur->next;}return cur->val;}void addAtHead(int val) {ListNode* head= new ListNode(val);head->next=dummyhead->next;dummyhead->next=head;size++;}void addAtTail(int val) {if(size==0) dummyhead->next=new ListNode(val);else{ListNode* cur=dummyhead->next;while(cur->next != NULL){cur=cur->next;}cur->next= new ListNode(val);}size++;}void addAtIndex(int index, int val) {if(index>size) return;ListNode* cur=dummyhead;for(int i=0;i<index;i++){cur=cur->next;}ListNode* temp=new ListNode(val);temp->next=cur->next;cur->next=temp;size++;}void deleteAtIndex(int index) {if(index>=size) return;ListNode* cur=dummyhead;for(int i=0;i<index;i++){cur=cur->next;};ListNode* temp=cur->next;cur->next=cur->next->next;delete temp;size--;}//void printLinkedList(){//}
private:int size;ListNode* dummyhead;
};

翻转链表

中间过程想到了用三个指针,双指针+储存临时下一个的指针。
但是开头和结尾的处理过程没想出来。
直接让pre=head,这样的话还得加上head->next=nullptr才表示一条链表结束了。
所以让pre=null就不用特殊处理开头和结尾了。

    ListNode* reverseList(ListNode* head) {//if(head->next==nullptr) return nullptr;//ListNode* dummyhead= new ListNode(0);//dummyhead->next=head;//ListNode* pre=head;//ListNode* cur=pre->next;//ListNode* next=cur->next;//cur->next=pre;//head=reversal(cur,next);//return head;if(head==nullptr) return nullptr;ListNode* pre=nullptr;ListNode* cur=head;while(cur!=nullptr){ListNode* next=cur->next;cur->next=pre;pre=cur;cur=next;}return pre;}

快忘记递归怎么写啦,就是递归套递归。

class Solution {
private:ListNode* reversal(ListNode* pre,ListNode* cur){if(cur==nullptr) return pre;ListNode* temp=cur->next;cur->next=pre;return reversal(cur,temp);}
public:ListNode* reverseList(ListNode* head) {ListNode* pre=nullptr;ListNode* cur=head;return reversal(pre,cur);}};
http://www.hkea.cn/news/413355/

相关文章:

  • 网站建设先做前台还是后台百度认证是什么
  • 广州专业做crm系统的供应商seo网站培训班
  • 景安建网站企业网站seo方案案例
  • 山东滕州疫情最新消息今天i长沙官网seo
  • 公司做网站买域名之后做什么百度一下你就知道手机版
  • 北京婚恋网站哪家最好企业推广宣传方式
  • 国发网站建设西安做网站公司
  • 网站推广服务合同简述网络营销的主要方法
  • 信息门户网站是什么成人计算机培训机构哪个最好
  • 网站建设公司 中企动力公司东莞商城网站建设
  • b2c的电子商务网站自己想做个网站怎么做
  • 京东pc网站用什么做的如何注册网站怎么注册
  • 长沙商城网站制作seo线下培训课程
  • web网站开发公司网站制作优化排名
  • 这么做3d网站企业邮箱网页版
  • 瑞安网站建设公司关键词排名网络推广
  • 南京学做网站友情链接检查工具
  • 参考文献网站开发百度重庆营销中心
  • 如何做微信ppt模板下载网站企业网页设计公司
  • 做b2b网站百度点击快速排名
  • 网站怎么做移动图片不显示不出来吗芭嘞seo
  • 旅游网站建设服务器ip域名解析
  • 企业网站建设三个原则百度指数资讯指数是指什么
  • 房地产集团网站建设方案软文文案案例
  • 阜蒙县建设学校网站是什么北京seo编辑
  • 珠海建设局网站十大经典事件营销案例分析
  • 创建网站开发公司互联网推广引流是做什么的
  • 万盛集团网站建设seo网站推广全程实例
  • 做教育的网站需要资质吗网站怎么开发
  • 微网站怎么做滚动中国万网域名注册官网