Prim算法

发布一个k8s部署视频:https://edu.youkuaiyun.com/course/detail/26967

课程内容:各种k8s部署方式。包括minikube部署,kubeadm部署,kubeasz部署,rancher部署,k3s部署。包括开发测试环境部署k8s,和生产环境部署k8s。

腾讯课堂连接地址https://ke.qq.com/course/478827?taid=4373109931462251&tuin=ba64518

第二个视频发布  https://edu.youkuaiyun.com/course/detail/27109

腾讯课堂连接地址https://ke.qq.com/course/484107?tuin=ba64518

介绍主要的k8s资源的使用配置和命令。包括configmap,pod,service,replicaset,namespace,deployment,daemonset,ingress,pv,pvc,sc,role,rolebinding,clusterrole,clusterrolebinding,secret,serviceaccount,statefulset,job,cronjob,podDisruptionbudget,podSecurityPolicy,networkPolicy,resourceQuota,limitrange,endpoint,event,conponentstatus,node,apiservice,controllerRevision等。

第三个视频发布:https://edu.youkuaiyun.com/course/detail/27574

详细介绍helm命令,学习helm chart语法,编写helm chart。深入分析各项目源码,学习编写helm插件
————————————————------------------------------------------------------------------------------------------------------------------

 

package com.data.struct;

import java.util.HashSet;
import java.util.Iterator;
import java.util.Random;
import java.util.Set;

public class Prim {
	private Node[] list;
	private Set<Node> restSet = new HashSet<Node>();
	private Set<Node> computedSet = new HashSet<Node>();

	public Prim(int v, int e) {
		System.out.println("v:" + v + " e:" + e);
		list = new Node[v];
		for (int i = 0; i < v; i++) {
			Node node = new Node();
			node.id = i;
			node.key = Integer.MAX_VALUE;
			list[i] = node;
		}
		System.out.print("weight:");
		for (int i = 0; i < e; i++) {
			int v1 = new Random().nextInt(v);
			int v2 = new Random().nextInt(v);
			if (v1 == v2) {
				continue;
			}
			while (true) {
				Node node = list[v1];
				Node x = node;
				boolean already = false;
				while (node.next != null) {
					if (node.next.id == v2) {
						already = true;
						break;
					}
					node = node.next;
				}
				if (already == true) {
					break;
				}
				Node ex = new Node();
				ex.id = v2;
				ex.w = new Random().nextInt(e);
				System.out.print(ex.w + " ");
				node.next = ex;
				break;
			}
		}
		System.out.println();
	}

	public void prim() {
		list[0].key = 0;
		computedSet.add(list[0]);
		for (int i = 1; i < list.length; i++) {
			restSet.add(list[i]);
		}
		
		Node w=list[0].next;
		Node u=list[0];
		while (w != null) {
			if(w.w<list[w.id].key){
				w.parent=u;
				w.key=w.w;
			}
			w = w.next;
		}


		while (restSet.size() > 0) {
			 u = extractMin();
			 if(u==null){
				 break;
			 }
			computedSet.add(u);
			 w=u.next;
			while (w != null) {
				Iterator<Node> it2 = computedSet.iterator();
				boolean has = false;
				while (it2.hasNext()) {
					if (w.id == it2.next().id) {
						has = true;
						break;
					}
				}
				if (!has) {
					if(w.w<list[w.id].key){
						list[w.id].parent=u;
						list[w.id].key=w.w;
					}
				}
				w = w.next;
			}

		}

	}

	public Node extractMin() {
		Iterator<Node> it = computedSet.iterator();
		int id = -1;
		int minW = Integer.MAX_VALUE;
		while (it.hasNext()) {
			Node node = it.next();
			Node w = node.next;
			while (w != null) {
				Iterator<Node> it2 = computedSet.iterator();
				boolean has = false;
				while (it2.hasNext()) {
					if (w.id == it2.next().id) {
						has = true;
						break;
					}
				}
				if (!has) {
					if (minW > w.w) {
						id = w.id;
						minW = w.w;
					}
				}
				w = w.next;
			}
		}
		if(id==-1){
			return null;
		}
		return list[id];
	}

	public void printG() {
		for (int i = 0; i < list.length; i++) {
			Node node = list[i];
			System.out.print(node.id + "=>");
			while (node.next != null) {
				System.out.print(node.next.id + "(" + node.next.w + ")=>");
				node = node.next;
			}
			System.out.println();
		}

	}
	
	public void printTree(){
		for(int i=0;i<list.length;i++){
			Node node=list[i];
			while(node.parent!=null){
			  System.out.print(node.id +" ");;
			  node=node.parent;
			}
			System.out.print(node.id+" ");
			System.out.println();
		}
	}

	public Node findSet(Node x) {
		if (x.parent != x) {
			x.parent = findSet(x.parent);
		}
		return x.parent;
	}

	public static class Node {
		private int id;
		private Node next;
		private int w;
		private int key;
		private Node parent;
	}

	public static void main(String[] args) {
		Prim p = new Prim(5, 20);
		p.printG();
		p.prim();
		p.printTree();

	}

}

 

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

hxpjava1

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值