当前位置: 首页 > 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.yidumall.com/news/54808.html

相关文章:

  • 建设一个网站需要哪些知识宁波seo公司
  • 适合大学生创业的网站建设类型百度贴吧官网app下载
  • 手机网站设计哪家好河北网站建设案例
  • 海南百度网站建设深圳网络推广团队
  • 搭建网站是什么意思站外seo是什么
  • 网站谷歌地图提交seo入口
  • 做民宿加盟哪些网站比较好百度检索入口
  • wordpress feed插件重庆关键词优化服务
  • 做网站需要什么步骤搜索引擎实训心得体会
  • 上海门户网站建设公司沈阳关键词优化费用
  • 做企业网站用二级域名好吗好的seo平台
  • 建网站赚钱吗sem推广是什么
  • 做黄金的分析师网站网站推广经验
  • 毕业设计做网站怎么样关键词优化排名工具
  • 网站建设如何包含数据库百度搜索结果优化
  • 做网站是先买域名网络广告宣传怎么做
  • 管理咨询人员的基本素质seo门户网
  • 做淘宝网站目的是什么网络广告策划书案例
  • 做一个网站要怎么做青岛网站seo
  • 张家界做网站的人谷歌优化培训
  • 做花茶的网站淘宝代运营公司十大排名
  • 可以做h5的软件seo自动排名软件
  • 北京网页制作公司物美价廉深圳seo优化培训
  • 个人做跨境电商的平台网站如何创建公司网站
  • 物流网站公司腾讯广告投放平台
  • 怎么做网站web品牌宣传活动策划方案
  • 专业网站建设商家网页设计免费模板
  • 页面布局标准格式网络推广和信息流优化一样么
  • 企必搜做网站电话营销外包公司
  • 如何做地图的ppt模板下载网站网站关键词