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

怎么做免费的产品网站中国互联网协会官网

怎么做免费的产品网站,中国互联网协会官网,甘肃企业网站建设,接做室内效果图的网站模拟实现LinkedList:下一篇文章 LinkedList底层是双向、不带头结点、非循环的链表 /*** LinkedList的模拟实现*单向 不带头 非循环链表实现*/ class SingleLinkedList {class ListNode {public int val;public ListNode next;public ListNode(int val) {this.val …

 模拟实现LinkedList:下一篇文章

LinkedList底层是双向、不带头结点、非循环的链表

/*** LinkedList的模拟实现*单向 不带头 非循环链表实现*/
class SingleLinkedList {class ListNode {public int val;public ListNode next;public ListNode(int val) {this.val = val;}}public ListNode head;//永远指向头结点//创建链表public void createList() {ListNode node1 = new ListNode(1);ListNode node2 = new ListNode(2);ListNode node3 = new ListNode(3);ListNode node4 = new ListNode(4);ListNode node5 = new ListNode(5);node1.next = node2;node2.next = node3;node3.next = node4;node4.next = node5;this.head = node1;}//显示public void display() {while (head != null) {System.out.print(head.val + " ");head = head.next;//head往后移}}//得到单链表的长度public int size() {ListNode cur = head;int count = 0;while (cur != null) {count++;cur = cur.next;}return count;}//清空public void clear() {this.head = null;}//头插法public void addFirst(int data) {ListNode node = new ListNode(data);node.next = head;head = node;}//尾插法public void addLast(int data) {ListNode cur = head;ListNode node = new ListNode(data);if (head == null) {head = node;}while (cur.next != null) {cur = cur.next;}cur.next = node;//这时cur就是尾巴节点}//在任意位置插入,第一个数据节点为0的下标public void addIndex(int index, int data) {ListNode node = new ListNode(data);int len = size();//0.判断index位置是否合法if (index < 0 || index > len) {return;//也可以抛异常}//1.先找到index-1的位置  下面有个findIndex方法ListNode cur = findIndex(index);//2.插入数据node.next = cur.next;cur.next = node;}private ListNode findIndex(int index) {ListNode cur = head;while (index - 1 != 0) {cur = cur.next;index--;}return cur;//index-1位置的节点}//查找是否包含关键字key是否在单链表当中public boolean contains(int key) {ListNode cur = head;while (cur != null) {if (cur.val == key) {return true;}cur = cur.next;}return false;}//删除第一次出现关键字为key的节点public void remove(int key) {if(head==null){return;}if(head.val==key){head=head.next;return;}ListNode prev = searchPrev(key);if (prev== null) {System.out.println("没有这个数据");return;}ListNode del=prev.next;prev.next=del.next;}private ListNode searchPrev(int key){ListNode prev=head;while(prev.next!=null){if(prev.next.val==key){return prev;}else{prev=prev.next;}}return null;}//删除所有值为key的节点public void removeAllkey(int key) {if(head==null){return;}ListNode cur=head.next;ListNode prev=head;while(cur!=null){if(cur.val==key){prev.next=cur.next;cur=cur.next;}else{prev=cur;cur=cur.next;}}if(head.val==key){head=head.next;}}
}
public class Test {public static void main(String[] args) {SingleLinkedList singleLinkedList=new SingleLinkedList();singleLinkedList.createList();singleLinkedList.display();}
}

此处只调用了createList()和display()。需要其他方法的自己可以在main中调用哦

http://www.dinnco.com/news/60306.html

相关文章:

  • 如何做网站的管理后台徐州网页关键词优化
  • 网络公司做网站后期注意山西网络推广专业
  • 用html做企业门户网站东莞企业网站推广
  • 万网怎么建设网站上海免费关键词排名优化
  • 2019为赌博网站做代理被判缓刑公司网站怎么做
  • asp.net网站开发代码网络软文营销案例
  • 网站备案注销外贸营销网站怎么建站
  • 易网官方网站seo软件简单易排名稳定
  • 网站黑名单查询武汉seo 网络推广
  • 新疆建设兵团医院网站优化是什么意思
  • 网站建设与网页制作做企业网站哪个平台好
  • 山西专业制作网站香港疫情最新情况
  • 廊坊网站开发公司站长工具的使用seo综合查询运营
  • 亚马逊网站开发设计社区建站网站系统
  • 学网站开发前景济南网站seo
  • 网站建设 国风网络一键优化大师
  • 蚌埠市建设局网站找培训班一般在什么平台
  • 外贸建站与推广如何做 google国内搜索引擎排名
  • 建设部人力资源开发中心网站百度账号怎么注销
  • 手机淘宝客网站怎么做的郑州官网关键词优化公司
  • seo案例seo推广方法集合
  • 沈阳建设公司网站下载百度免费
  • 北京市住房与城乡建设厅网站春哥seo博客
  • 网站小程序怎么做优化游戏卡顿的软件
  • 加强政府网站建设seo的外链平台有哪些
  • ppt做书模板下载网站有哪些百度快速排名案例
  • 随州学做网站公司网站建设方案
  • 如何做网站程序百度服务热线
  • 广西建设厅网站首页百度账户托管运营
  • 邢台123网站口碑营销的产品有哪些