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

小说主角王烨郑州网站推广优化

小说主角王烨,郑州网站推广优化,用java做的网站怎么发布,手机网站建站教程在使用以下方法时需要定义一个LinkNode类来定义变量,new一个新对象进行调用,输出时需要定义输出方法 public class ListNode {int value;ListNode next;//public ListNode(int value) {this.value value;}public String toString(){return "ListN…

        在使用以下方法时需要定义一个LinkNode类来定义变量,new一个新对象进行调用,输出时需要定义输出方法

public class ListNode {int value;ListNode next;//public ListNode(int value) {this.value = value;}public String toString(){return "ListNode [value=" + value+", next="+next+"]";}public String toString1(){return "ListNode [value=" + value+"]";}
}

 定义下面方法时需要提前定义头指针

public ListNode head = null;//定义头指针

1.插入,尾插法

//插入,尾插法public void insert(int value){ListNode node = new ListNode(value);if(head==null){head=node;return;}ListNode index = head;while (index.next!=null){index = index.next;}index.next=node;}

2.插入,头插法

//插入,头插法public void headinsert(int value){ListNode node = new ListNode(value);if(head==null){head=node;return;}node.next=head;head=node;}

3.输出链表上的值 

//输出链表上的值public void printLink1(){ListNode index = head;while (index.next!=null){//最后一个value不进入循环System.out.print(index.value+" ");index = index.next;}System.out.println(index.value);}//输出链表上的值public void printLink2(){ListNode index = head;while (index!=null) {//最后一个value进入循环System.out.print(index.value+" ");index = index.next;}}

4.输出链表长度

//输出链表长度public int getListLength(){int temp=0;ListNode index = head;while (index!=null){temp++;index =index.next;}return temp;}

5.查找某个元素是否在链表上

//查找某个元素是否在链表上public boolean contains(int a){boolean b= false;ListNode index =head;if (head==null){b = false;}while (index!=null){if (index.value == a){b= true;}else {b=false;}index =index.next;}return b;}

6.任意位置插入

 //任意位置插入public void addNodeAtIndex(int value,int position){//判断插入位置是否合法if(position<0||position>getListLength()){System.out.println("插入位置不合法");return;}if (position==0){headinsert(value);}else if (position==getListLength()){insert(value);}else {//创建新节点ListNode node = new ListNode(value);ListNode index = head;ListNode pre = null;//找相关位置int count=0;while (index!=null){if (count==position){node.next=index;pre.next=node;return;}pre=index;index=index.next;count++;}}}

7.任意位置删除 

//任意位置删除public void deleteNodeAtIndex(int position){//判断插入位置是否合法if(position<0||position>getListLength()-1){System.out.println("删除位置不合法");return;}//删除位置是0号位置if (position==0){head=head.next;return;}//删除位置不是0号位置ListNode index = head;ListNode pre = null;//找相关位置int count=0;while (index!=null){if (count==position){pre.next=index.next;return;}pre=index;index=index.next;count++;}}

 8.找中间节点,只遍历一次

//找到中间节点,只遍历一遍public ListNode findMiddle(){ListNode fast = head;ListNode show = head;while (fast!=null&&fast.next!=null){fast=fast.next.next;show=show.next;}return show;}

9.判断链表是否成环

 //判断链表是否成环public boolean hasCycle(){ListNode fast = head;ListNode show = head;while (fast!=null&&fast.next!=null){fast=fast.next.next;show=show.next;if (fast==show){return true;}}return false;}

10.判断成环链表的起始节点 

 //判断成环链表的起始节点public ListNode findHasCycle(){ListNode fast = head;ListNode show = head;while (fast!=null&&fast.next!=null){fast=fast.next.next;show=show.next;if (fast==show){show=head;while (show!=fast){fast= fast.next;show= show.next;}return show;}}return null;}

11.截取单链表后k个节点

 //截取单链表后k个节点public ListNode endNode(int k){ListNode fast = head;ListNode show = head;//fast先走k步for (int i = 0; i < k; i++) {fast=fast.next;}while (fast!=null){show= show.next;fast= fast.next;}return show;}

12.翻转链表,在链表上直接翻转 

//翻转链表,在链表上直接翻转public ListNode fanzhuan(){ListNode index = null;ListNode pre = null;while (head!=null){index=head.next;head.next=pre;pre=head;head=index;}head=pre;return head;}

 

 

 

 

 

 

http://www.wangmingla.cn/news/36425.html

相关文章:

  • 赣县网站制作深圳互联网公司排行榜
  • 设计类专业考研考什么百度推广关键词怎么优化
  • 深圳 网站建设培训学校百度电脑版
  • 佛山微信网站建设多少钱中国最新军事新闻
  • 佛山中小企业网站制作seo推广策略
  • 广西网站建设seo具体怎么优化
  • 聊城手机网站制作刷关键词指数
  • 我想学制作网站吗百度引流推广哪家好
  • 如何招网站开发人员微信朋友圈广告30元 1000次
  • 阿里巴巴有几个网站是做外贸的公关团队
  • 上海做网站好的公司有哪些手机优化助手
  • 用宝塔给远程网站做备份万网域名注册查询
  • 淘宝店铺做网站收录谈谈你对seo概念的理解
  • 设计公司品牌介绍中山seo
  • 如何自己做网站界面seo网站排名优化快速排
  • 中小企业网站制作公司今日刚刚发生的新闻
  • wordpress头像上传优化大师电脑版官网
  • 杭州手机申请网站登录seo赚钱方法大揭秘
  • 广东君冠建设有限公司网站网络营销推广优化
  • 为什么企业需要建设网站?在线友情链接
  • 陕西网站建设公司哪有整站优化代理
  • 手机购物网站模板市场监督管理局投诉电话
  • 国外网站建设官网百度关键词推广怎么做
  • 网站建设仿站专业海外网站推广
  • 无锡信息网招聘武汉seo排名扣费
  • 做网站的要到处跑吗百度网站官网网址
  • 做视频网站技术壁垒在哪里推广员是做什么的
  • 申报网站百度关键词搜索排名多少钱
  • 建设银行网上流览网站东莞网络营销渠道
  • js 网站源码百度指数官网查询入口