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

芸志建站怎么建立网站手把手教你做网站7

芸志建站怎么建立网站,手把手教你做网站7,24小时最新国际新闻,做网站字体用什么格式理论 链表的增删操作时间复杂度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-nexthead;ListNode* curdummyhead;while(cur-next!NULL){if(cur-next-val val){ListNode* tempcur-next;cur-next cur-next-next;delete temp;}else{curcur-next;}}return dummyhead-next;} };设计链表 总是忘记判定插入或者删除的位置是否有效。 class MyLinkedList { public:struct ListNode {int val;ListNode *next;ListNode(int val) : val(val), next(nullptr) {}};MyLinkedList() {dummyheadnew ListNode(0);size0;}int get(int index) {if(indexsize-1)return -1;ListNode* curdummyhead-next;for(int i0;iindex;i){curcur-next;}return cur-val;}void addAtHead(int val) {ListNode* head new ListNode(val);head-nextdummyhead-next;dummyhead-nexthead;size;}void addAtTail(int val) {if(size0) dummyhead-nextnew ListNode(val);else{ListNode* curdummyhead-next;while(cur-next ! NULL){curcur-next;}cur-next new ListNode(val);}size;}void addAtIndex(int index, int val) {if(indexsize) return;ListNode* curdummyhead;for(int i0;iindex;i){curcur-next;}ListNode* tempnew ListNode(val);temp-nextcur-next;cur-nexttemp;size;}void deleteAtIndex(int index) {if(indexsize) return;ListNode* curdummyhead;for(int i0;iindex;i){curcur-next;};ListNode* tempcur-next;cur-nextcur-next-next;delete temp;size--;}//void printLinkedList(){//} private:int size;ListNode* dummyhead; };翻转链表 中间过程想到了用三个指针双指针储存临时下一个的指针。 但是开头和结尾的处理过程没想出来。 直接让prehead,这样的话还得加上head-nextnullptr才表示一条链表结束了。 所以让prenull就不用特殊处理开头和结尾了。 ListNode* reverseList(ListNode* head) {//if(head-nextnullptr) return nullptr;//ListNode* dummyhead new ListNode(0);//dummyhead-nexthead;//ListNode* prehead;//ListNode* curpre-next;//ListNode* nextcur-next;//cur-nextpre;//headreversal(cur,next);//return head;if(headnullptr) return nullptr;ListNode* prenullptr;ListNode* curhead;while(cur!nullptr){ListNode* nextcur-next;cur-nextpre;precur;curnext;}return pre;}快忘记递归怎么写啦就是递归套递归。 class Solution { private:ListNode* reversal(ListNode* pre,ListNode* cur){if(curnullptr) return pre;ListNode* tempcur-next;cur-nextpre;return reversal(cur,temp);} public:ListNode* reverseList(ListNode* head) {ListNode* prenullptr;ListNode* curhead;return reversal(pre,cur);}};
http://www.dnsts.com.cn/news/47678.html

相关文章:

  • 模仿建设网站是侵权吗wordpress做多重筛选
  • 网站滑动效果怎么做的3g版和wap网站
  • 制作个人网站教程服务类的网站怎么做
  • 网站建设定制设计实时国际新闻app
  • 鲜花商城网站设计北京网站备案核验单
  • 建立一个企业网站注册一个网站要多少费用
  • 建德营销型网站建设主题字体怎么设置 wordpress
  • 集团网站建设基础方案小程序大概需要多少钱
  • 建设单位企业锁登陆网站做一个京东这样的网站需要多少钱
  • 小说网站有源码了该怎么做万维网网站域名续费
  • 苏州网站建设一条龙请问做网站需要什么
  • 医药网站制作建网站哪个公司好
  • 珠海市建设局官方网站wordpress 邮件 key
  • 人人商城程序做的网站打不开WordPress随机置顶插件
  • 公司网站建设济宁昆明网络推广公司排名
  • 百度里面的站长工具怎么取消wordpress如何设置文章模板
  • 常州专业网站建设公司百度云域名没有备案怎么做网站
  • 网站公司做文员聊城集团网站建设加盟
  • 网站建设选择本地网站开发维护协议
  • 网站做线支付平台系统多少钱哪个网站专门做游戏脚本
  • 个人可以做自媒体网站吗教育培训的网站建设
  • php网站管理系统下载时代空间网站
  • 淘宝做网站的都是模板jw网站设计
  • 做网站的时候宽度都怎么弄程序员做电商网站的公司好吗
  • 苏州学习网站建设网站备案幕布多少钱
  • 舆情网站直接打开怎么弄网站上传都传些什么文件
  • 网站自动发送邮件德州市德城区城乡建设局网站
  • 企业网站备案代理公司做h5小游戏的网站有哪些
  • 网站关键词如何选取正规代运营公司排名
  • 网站建设 的系统公式1万网站建设费入什么科目