数据结构与算法--第3篇(Jusephu问题)

一,环形队列

1,单项环形链表

1.1,分析:

构建环形链表

  1. 先创建一个节点first,自己指向自己,形成闭环;
  2. 再增加的节点都按照第一个节点的next指向新增节点,而新增节点的next指向第一个节点,再次形成闭环;

遍历环形链表

  1. 先创建一个辅助节点current,指向第一个节点;
  2. 再通过while循环遍历各个节点,当current.next==first节点时说明遍历结束;

定义boy:

package com.linkedList;

/**
 * @param
 * @Author: AaNeei
 * @Date: 2019/6/13  21:58
 * @Description: 游学网
 * @throws:
 */
public class Boy {
   
    private int no;
    private Boy next;

    public Boy(int no) {
   
        this.no = no;
    }

    public int getNo() {
   
        return no;
    }

    public void setNo(int no) {
   
        this.no = no;
    }

    public Boy getNext() {
   
        return next;
    }

    public void setNext(Boy next) {
   
        this.next = next;
    }
}

定义环形单项链表:

package com.linkedList;

/**
 1. @param
 2. @Author: AaNeei
 3. @Date: 2019/6/13  21:59
 4. @Description: 游学网
 5. @throws:
 */
public class 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值