栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

组建树状数据结构算法

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

组建树状数据结构算法

前言

提示:平铺数据转为层级树状数据结构


一、代码如下:
		//查询数据源信息
        List jyeooSectionPos = getJyeooSectionPos(bookId);
        if (!CollectionUtils.isEmpty(jyeooSectionPos)) {
            //2.组装成知识点树
            List yunhenPointVos = new ArrayList<>();
            if (CollectionUtils.isEmpty(jyeooSectionPos)) {
                return ResultUtil.createResult(true, "查询成功!", yunhenPointVos);
            }
            if (!CollectionUtils.isEmpty(jyeooSectionPos)) {
                for (JyeooSectionPo yunhenPointPo : jyeooSectionPos) {
                    JyeooSectionTreeOutVo yunhenPointVo = new JyeooSectionTreeOutVo();
                    BeanUtil.copyProperties(yunhenPointPo, yunhenPointVo);
                    yunhenPointVos.add(yunhenPointVo);
                }
            }
            //获取第一层知识点
            List firstLevelPoints = new ArrayList<>();
            for (JyeooSectionTreeOutVo yunhenPointVo : yunhenPointVos) {
                String pid = yunhenPointVo.getPid();
                if (StringUtils.isEmpty(pid)) {
                    firstLevelPoints.add(yunhenPointVo);
                    List subPointTree = getPointTree(yunhenPointVos, yunhenPointVo.getId());
                    yunhenPointVo.setChildren(subPointTree);
                }
                //可以排序
            }
            return ResultUtil.createResult(true, "查询成功!", firstLevelPoints);
        }
 
    public List getPointTree(List yunhenPointVos, String id) {
        if (yunhenPointVos == null || yunhenPointVos.size() == 0) {
            return null;
        }
        List list = new ArrayList<>();
        List listContinue = new ArrayList<>(yunhenPointVos);

        for (JyeooSectionTreeOutVo yunhenPointVo : yunhenPointVos) {
            if (id.equals(yunhenPointVo.getPid())) {
                listContinue.remove(yunhenPointVo);
                yunhenPointVo.setChildren(getPointTree(listContinue, yunhenPointVo.getId()));
                list.add(yunhenPointVo);
            }
        }
        if (list.size() == 0) {
            return null;
        }
        return list;
    }
2.JyeooSectionTreeOutVo实体

代码如下(示例):

package com.yunhenedu.homework.vo;

import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

@Data
public class JyeooSectionTreeOutVo implements Cloneable, Serializable {
    
    private String id;

    
    private String jyeooId;

    
    private String pjyeooId;

    
    private String pid;

    
    private String seq;

    
    private String name;

    
    private String describes;

    
    private String editionDetailId;

    
    private String editionDetailJyeooId;

    
    private String subjectEn;

    @ApiModelProperty("子知识点列表")
    private List children;
}

该处使用的url网络请求的数据。


总结

提示:这里对文章进行总结:
例如:以上就是今天要讲的内容,本文仅仅简单介绍了pandas的使用,而pandas提供了大量能使我们快速便捷地处理数据的函数和方法。

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/877950.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号