数据结构-裴波那契堆实现

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

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

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

第二个视频发布  https://edu.csdn.net/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.csdn.net/course/detail/27574

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

 

package com.data.struct;


public class FibHeap {
	private Node min;
	private int n;
	
	public  FibHeap(){
		
	}
	
	public FibHeap(int [] data){
		for(int i=0;i<data.length;i++){
			insert(data[i]);
		}
	}
	
	public void insert(int key){
		Node node=new Node();
		node.key=key;
		insert(node);
	}
	
	public void insert(Node node){
		node.degree=0;
		node.parent=null;
		node.children=null;
		node.mark=false;
		if(min==null){
			min=node;
			min.left=min;
			min.right=min;
		}else{
			min.right.left=node;
			node.right=min.right;
			min.right=node;
			node.left=min;
			if(node.key<min.key){
				min=node;
			}
		}
		n=n+1;
	}
	
	public FibHeap union(FibHeap fib){
		FibHeap h=new FibHeap();
		h.min=this.min;
		h.min.right.left=fib.min.right;
		fib.min.right.right=h.min.right;
		fib.min.left=h.min;
		h.min.right=fib.min;
		if(this.min==null||fib.min!=null&&fib.min.key<h.min.key){
			h.min=fib.min;
		}
		h.n=this.n+fib.n;
		return h;
	}
	
	public Node extractMin(){
		Node z=min;
		if(z!=null){
			if(z.children!=null){
				Node c=z.children;
				Node right=c.right;
				this.min.right.left=c;
				c.right=this.min.right;
				c.left=this.min;
				this.min.right=c;
				c.parent=null;
				c=right;
				while(c.right!=z.children.right){
					this.min.right.left=c;
					c.right=this.min.right;
					c.left=this.min;
					this.min.right=c;
					c.parent=null;
					c=c.right;
				}
			}
			
			this.min.right.left=this.min.left;
			this.min.left.right=this.min.right;
			if(z==z.right){
				min=null;
			}else{
				min=z.right;
				consolidate();
			}
			n=n-1;
		}
		return z;
	}
	
	private void consolidate(){
		Node []a=new Node[n];
		for(int i=0;i<a.length;i++){
			a[i]=null;;
		}
		Node w=min;
		Node x=w;
		int d=x.degree;
		Node right=w.right;
		while(a[d]!=null){
			Node y=a[d];
			if(x.key>y.key){
				Node tmp=x;
				x=y;
				y=tmp;
			}
			if(y==min){
				min=min.right;
			}
			link(y,x);
			a[d]=null;
			d=d+1;
		}
		a[d]=x;
		w=right;
		while( w.right!=min.right){
			Node z=w;
			d=z.degree;
			right=w.right;
			while(a[d]!=null){
				Node y=a[d];
				if(z.key>y.key){
					Node tmp=z;
					z=y;
					y=tmp;
				}
				if(y==min){
					min=min.right;
				}
				link(y,z);
				a[d]=null;
				d=d+1;
			}
			a[d]=z;
			w=right;
		}
		min=null;
		for(int i=0;i<a.length;i++){
			if(a[i]!=null){
				if(min==null){
					min=a[i];
					min.right=min;
					min.left=min;
				}else{
					min.right.left=a[i];
					a[i].right=min.right;
					a[i].left=min;
					min.right=a[i];
					if(a[i].key<min.key){
						min=a[i];
					}
				}
			}
		}
		
		
	}
	
	private void link(Node y,Node x){
		y.right.left=y.left;
		y.left.right=y.right;
		if(x.children==null){
			x.children=y;
			y.right=y;
			y.left=y;
		}else{
			x.children.right.left=y;
			y.right=x.children.right;
			x.children.right=y;
			y.left=x.children;
		}
		y.parent=x;
		x.degree++;
		y.mark=false;
	}
	
	public void decreaseKey(Node x,int k)throws  Exception{
		if(k>x.key){
			throw new Exception("new key is grater than crurrent key");
		}
		x.key=k;
		Node y=x.parent;
		if(y!=null&&x.key<y.key){
			cut(x,y);
			cascadingCut(y);
		}
		if(x.key<min.key){
			min=x;
		}
	}
	private void cut(Node x,Node y){
		x.right.left=x.left;
		x.left.right=x.right;
		min.right.left=x;
		x.right=min.right;
		x.left=min;
		min.right=x;
		x.parent=null;
		x.mark=false;
	}
	
	private void cascadingCut(Node y){
		Node z=y.parent;
		if(z!=null){
			if(!y.mark){
				y.mark=true;
			}else{
				cut(y,z);
				cascadingCut(z);
			}
		}
	}
	
	public void delete(Node x)throws Exception{
		decreaseKey(x, Integer.MIN_VALUE);
		extractMin();
	}
	
	public Node find(int key){
		return find(min,key);
	}
	
	private Node find(Node node,int key){
		if(node==null){
			return null;
		}
		Node p=node;
		if(p.key==key){
			return p;
		}
		Node z=find(p.children,key);
		if(z!=null){
			return z;
		}
		p=p.right;
		while(p!=node){
			if(p.key==key){
				return p;
			}
			 z=find(p.children,key);
			if(z!=null){
				return z;
			}
			p=p.right;
		}
		return null;
	}
	
	
	 public void print(){
	        System.out.format("F-Heap(n=%d):%n",this.n);
	        Node h = this.min;
	        while(h!=null){
	            this.print(0, h);
	            h = (h.right!=min)?h.right:null;
	        }
	    }
	     
    private void print(int level, Node node){
        for (int i = 0; i < level; i++) {
            System.out.format(" ");
        }
        System.out.format("|");
        for (int i = 0; i < level; i++) {
            System.out.format("-");
        }
        
        System.out.format("%d%s%n", node.key,node.mark?"(x)":"");
        Node child = node.children;
        while(child!=null){         
            print(level + 1, child);
            child = (child.right!=node.children)?child.right:null;
        }           
    }
	
	private static class Node{
		private int degree;
		private Node parent;
		private Node children;
		private boolean mark;
		private Node left;
		private Node right;
		private int key;
		
		
	}
	
	
	public static void main(String[] args)throws Exception {
		/*int []data=new int[]{1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};
		FibHeap fib=new FibHeap(data);
		fib.print();
		Node a=fib.find(3);
		System.out.println(a.key);
		fib.delete(a);
		System.out.println("==============");
		fib.print();*/
		System.out.println("===========");
		int []data2=new int[]{15,14,13,12,11,10,9,8,7,6,5,4,3,2,1};
		FibHeap fib2=new FibHeap(data2);
		Node a2=fib2.find(3);
		fib2.delete(a2);
		fib2.print();
		Node a3=fib2.find(10);
		fib2.delete(a3);
		Node a4=fib2.find(6);
		fib2.delete(a4);
		fib2.print();
		System.out.println("==============");
	}

}

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

hxpjava1

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

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

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

打赏作者

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

抵扣说明:

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

余额充值