亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? fibonacciheap.java

?? This code implements the shortest path algorithm via the simple scheme and fibonacci heap data struc
?? JAVA
字號:


public class FibonacciHeap {
	public FibonacciNode root;
	
	public FibonacciHeap(){
		root=null;
	}
	
	public FibonacciHeap(FibonacciNode min){
		root=min;
	}
	
	public boolean isEmpty(){
		//see if the heap is empty
		if(root==null)
			return false;
		else
			return true;
	}
	
	public void Meld(FibonacciHeap f){
		//meld f with the original heap
		FibonacciNode Foriginal;
		FibonacciNode F;
		
		Foriginal=root;
		while(!Foriginal.RightSibling.equals(root))
			Foriginal=Foriginal.RightSibling;
		
		F=f.root;
		while(!F.RightSibling.equals(F))
			F=F.RightSibling;
		
		Foriginal.LeftSibling.RightSibling=F;
		F.LeftSibling.RightSibling=Foriginal;
		FibonacciNode Froot=F.LeftSibling;
		F.LeftSibling=Foriginal.LeftSibling;
		Foriginal.LeftSibling=Froot;
		
		if(f.root.dist<root.dist){
			root=f.root;  
		}
	}
	
	public void Insert(FibonacciNode f){
		//insert f into the orignial heap
		f.LeftSibling=null;
		f.RightSibling=null;
		f.Parent=null;

        //If empty
		if(root==null){
			root=f;
			f.LeftSibling=f;
			f.RightSibling=f;
		}
		else{
			//If there is only one node in the first level
			if(root.RightSibling.equals(root)&& root.LeftSibling.equals(root))
			{
				root.LeftSibling=f;
				root.RightSibling=f;
				f.LeftSibling=root;
				f.RightSibling=root;
			}
			//If there is two or two more node in the first level
			else{
				f.RightSibling=root.RightSibling;
				f.LeftSibling=root;
				root.RightSibling.LeftSibling=f;
				root.RightSibling=f;
			}			
		}
		//If the minroot is less than the node to be inserted, change the minroot pointer
		if(f.dist<root.dist){
			root=f;
		}
	}
	
	private void PairwiseCombine(){
		//pairwise combine two trees with same degree
		if(root==null)
		return;
		if(!root.RightSibling.equals(root)&&!root.LeftSibling.equals(root)){
			int NumOfSibling=0;
			for(FibonacciNode Fnode=root.RightSibling;!Fnode.equals(root);Fnode=Fnode.RightSibling)
				NumOfSibling++;  
			
			FibonacciHeap treetable[]=new FibonacciHeap[1000];
			//initialize the degree table
			FibonacciHeap heap[] = new FibonacciHeap[NumOfSibling+1];;
			boolean combine[]= new boolean[NumOfSibling+1];;
		
			int i=0;
			for(FibonacciNode Fnode=root;i<=NumOfSibling;i++,Fnode=Fnode.RightSibling){
				heap[i]=new FibonacciHeap(Fnode); 
				combine[i]=false;
			}
	
			for(int j=0;j<=NumOfSibling;j++){
				heap[j].root.LeftSibling=heap[j].root;
				heap[j].root.RightSibling=heap[j].root;
				heap[j].root.Parent=null;
			}
			
			for(int j=0;j<=NumOfSibling;j++){
				int degree;
				FibonacciHeap p1;
				FibonacciHeap p2=heap[j];
				degree = heap[j].root.degree;
					
				// combine the heaps until the degree table is null
				while(treetable[degree]!=null)
				{
					p1=treetable[degree];				
					if(p1.root.dist>p2.root.dist){
						int m=0;
						for(int k=0;k<=NumOfSibling;k++){
							if(heap[k].equals(p1)){
								m=k;
							}
						}
						combine[m]=true;
						FibonacciHeap t=p1;
						p1=p2;
						p2=t;
					}
					else{
						int m=0;
						for(int k=0;k<=NumOfSibling;k++){
							if(heap[k].equals(p2)){
								m=k;
							}
						}
						combine[m]=true;
					}
					
					//combine the p1 and p2
					//if p1.min has no children
					if(p1.root.FirstChild!=null)
					{
						//if p1.min has only one first vhild 
						if(p1.root.degree==1){
							p1.root.FirstChild.RightSibling=p2.root;
							p1.root.FirstChild.LeftSibling=p2.root;
							p2.root.RightSibling=p1.root.FirstChild;
							p2.root.LeftSibling=p1.root.FirstChild;
							p2.root.Parent=p1.root;
							p1.root.degree++;
							p2.root.ChildCut=false;

						}
						//if p1.min has two or more than two first children
						else{
							FibonacciNode p=p1.root.FirstChild;
							for(int k=0;k<=p1.root.degree-2&&p.RightSibling!=null;k++){
								p=p.RightSibling;
							}
							p.RightSibling=p2.root;
							p2.root.LeftSibling=p;
							p2.root.RightSibling=p1.root.FirstChild;
							p1.root.FirstChild.LeftSibling=p2.root;
							p1.root.degree++;
							p2.root.ChildCut=false;
							p2.root.Parent=p1.root;
							
						}
					}
					else{
						p1.root.FirstChild=p2.root;
						p2.root.ChildCut=false;
						p2.root.Parent=p1.root;
						p1.root.degree++;
					}
					p2=p1;              
					// make the two heaps become one heap
					treetable[degree]=null; 
					// the orginal degree table set to null
					degree++;  
					// after combinantion, degree increase by 1
				}
				treetable[degree]=p2; 
				// insert the newly combined heap or sole heap in the degree table
			}
			int j;
			for( j=0;j<=NumOfSibling;j++){
				if(combine[j]==false){
					root=heap[j].root; 
					//find the root after pairwise combine
					break;
				}
			}
			for(int k=j+1;k<=NumOfSibling;k++){
				if(combine[k]==false)
					Meld(heap[k]);   
				// link the remaining heaps in the fisrt level
			}
		}
	}
	
	public void RemoveMinroot(){
		//If there is only one node in the first level
		if(root.RightSibling.equals(root)&&root.LeftSibling.equals(root)){
			root=null; // free the root
		}
		
		//If there is two or two nodes in the first level
		else{
			root.LeftSibling.RightSibling=root.RightSibling;
			root.RightSibling.LeftSibling=root.LeftSibling;
			root=root.RightSibling;	
			//If more than one node LeftSibling after deletion
			if(!root.RightSibling.equals(root)&&!root.LeftSibling.equals(root)){
				FibonacciNode Fnode=root,Fnoderoot=root;
				// find the root from the node in the first level
				for(;!Fnode.RightSibling.equals(root);Fnode=Fnode.RightSibling){
					if(Fnode.dist<Fnoderoot.dist){
						Fnoderoot=Fnode;
					}
				}
				root=Fnoderoot;
			}
		}
	}
	
	public FibonacciNode DeleteMin(){
        //If the Heap is Empty
		if(isEmpty()==false)
			return null;
		FibonacciNode Min=root;
        //If root has some FirstChildren
		if(root.FirstChild!=null){		
        //If root has only one FirstChild
			if(root.degree==1){
				FibonacciNode minFirstChild=root.FirstChild;
				RemoveMinroot();
				Insert(minFirstChild);
			}
            //If min has more than one FirstChildren
			else{
				int degree=root.degree-1;
				FibonacciNode minFirstChild=root.FirstChild;
				FibonacciNode FirstChild[]=new FibonacciNode[root.degree];
				// save the root's FirstChildren in a FibonacciNode Array to be inserted later
				for(int i=0;i<=root.degree-1&&minFirstChild!=null;i++,minFirstChild=minFirstChild.RightSibling){
					FirstChild[i]=minFirstChild;
				}
				//after saving the root's FirstChildren, we can delete the root
				RemoveMinroot();
				//insert the remaining FirstChildren into heap in order
				for(int i=0;i<=degree;i++){
					Insert(FirstChild[i]);
				}

			}
		}
		//If the root has no FirstChild
		else{
			RemoveMinroot();
		}
		//combine the remaining heaps pairwise at last
		PairwiseCombine();
		return Min;
	}
	
	private void CutHeap(FibonacciNode x, FibonacciNode P){
		//remove x from first child list of P
		if(P.degree==1){
			P.degree--;
			P.FirstChild=null;
			x.LeftSibling=null;
			x.RightSibling=null;
		}
		else{
			if(P.FirstChild.equals(x)){
				P.degree--;
				P.FirstChild=x.RightSibling;
				x.RightSibling.LeftSibling=x.LeftSibling;
				x.LeftSibling.RightSibling=x.RightSibling;
				x.LeftSibling=null;
				x.RightSibling=null;
			}
			else{
				P.degree--;
				FibonacciNode Fnode=P.FirstChild;
				for(int i=0;i<=P.degree-1&&!Fnode.equals(x);i++,Fnode=Fnode.RightSibling)
					; // find the node x to be cut and cut it
				x.LeftSibling.RightSibling=x.RightSibling;
				x.RightSibling.LeftSibling=x.LeftSibling;
				x.LeftSibling=null;
				x.RightSibling=null;
			}
		}
		//insert x to the first level
		if(root.RightSibling.equals(root)&&root.LeftSibling.equals(root)){
			root.RightSibling=x;
			root.LeftSibling=x;
			x.LeftSibling=root;
			x.RightSibling=root;
		}
		else{
			root.RightSibling.LeftSibling=x;
			x.RightSibling=root.RightSibling;
			root.RightSibling=x;
			x.LeftSibling=root;
		}
		x.Parent=null;
		x.ChildCut=false;  
		// if the node in first level, the attribute ChildCut should be false
	}
	
	private void CascadingCut(FibonacciNode y){
		FibonacciNode Parent=y.Parent;
		if(Parent!=null){
			// if the ChildCut=true, make it false
			if(y.ChildCut==false)
				y.ChildCut=true;  
			else{
				CutHeap(y, Parent);  // cut it from the heap
				CascadingCut(Parent);  // cut it recursively
			}
		}
	}
	
	public void DecreaseKey(FibonacciNode x, int value){
		if(root==null)
			return;
		if(x.LeftSibling!=null&&x.RightSibling!=null){
				x.dist=x.dist-value;
				FibonacciNode y=x.Parent;
				if(y!=null&&x.dist<y.dist){
					CutHeap(x, y); 
					//cut the node from the Parent
					CascadingCut(y); 
					// continue to cut if the Parent's Childcut is ture
				}
			
			if(x.dist<root.dist)
				root=x;
		}
	}

}

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
国产精品妹子av| 国产麻豆9l精品三级站| 亚洲婷婷国产精品电影人久久| 久久综合av免费| 精品人在线二区三区| 日韩视频免费观看高清完整版 | 久久美女艺术照精彩视频福利播放| 欧美精品高清视频| 欧美精品xxxxbbbb| 欧美一区二区三区人| 日韩欧美三级在线| 欧美精品一区二区三区很污很色的| 欧美大尺度电影在线| 欧美成人伊人久久综合网| 亚洲一级二级在线| 亚洲自拍偷拍av| 偷窥国产亚洲免费视频| 日韩一区欧美二区| 麻豆极品一区二区三区| 精彩视频一区二区| 国产盗摄一区二区| 99久精品国产| 欧美日韩一区视频| 91精品国产综合久久久久久漫画| 日韩一区二区三区在线观看| 精品久久久久一区二区国产| 国产清纯白嫩初高生在线观看91| 久久久国产午夜精品| 中文字幕日韩一区| 亚洲成人一区二区| 久久激五月天综合精品| 丁香婷婷综合激情五月色| 91麻豆精品秘密| 91精品国产综合久久福利 | 国产精品女主播av| 亚洲美女视频在线观看| 日韩激情中文字幕| 国产成人免费av在线| 一本久久a久久精品亚洲| 欧美性猛交xxxxxxxx| 欧美成人猛片aaaaaaa| 国产拍欧美日韩视频二区| 亚洲日本在线天堂| 奇米一区二区三区| 不卡的av中国片| 7777精品伊人久久久大香线蕉超级流畅 | 一区二区三区 在线观看视频| 天天做天天摸天天爽国产一区| 精品在线播放午夜| 91在线精品一区二区| 一级女性全黄久久生活片免费| 麻豆精品在线看| 91影视在线播放| 日韩欧美亚洲国产另类| 亚洲欧洲另类国产综合| 麻豆视频观看网址久久| 92精品国产成人观看免费| 欧美一区二区三区日韩| 亚洲视频一区二区免费在线观看| 免费欧美日韩国产三级电影| av亚洲精华国产精华精华| 日韩一卡二卡三卡四卡| 亚洲人成网站在线| 国产一区二区免费看| 欧美日韩国产三级| 国产精品久久夜| 久久99国产精品久久99| 欧美在线免费观看视频| 欧美高清在线视频| 麻豆国产欧美一区二区三区| 欧美优质美女网站| 亚洲国产成人私人影院tom| 免费观看在线色综合| 日本精品视频一区二区| 国产欧美精品一区aⅴ影院| 婷婷丁香激情综合| 99久久精品免费| 国产亚洲一二三区| 裸体歌舞表演一区二区| 在线观看视频一区| 成人欧美一区二区三区小说 | eeuss鲁一区二区三区| 精品人伦一区二区色婷婷| 偷拍日韩校园综合在线| 一本高清dvd不卡在线观看| 国产精品久久午夜| 国产精品综合一区二区三区| 91精品国产色综合久久久蜜香臀| 亚洲一区二区黄色| 91最新地址在线播放| 国产精品国模大尺度视频| 国产精品一区2区| 精品福利一区二区三区| 久久9热精品视频| 亚洲网友自拍偷拍| 一本大道av伊人久久综合| 国产精品传媒入口麻豆| 成人性生交大合| 国产精品网站在线观看| 国产大片一区二区| 久久精品一区二区三区不卡牛牛| 另类成人小视频在线| 日韩午夜激情视频| 日本麻豆一区二区三区视频| 欧美区视频在线观看| 午夜精品爽啪视频| 欧美精品日韩精品| 青娱乐精品在线视频| 欧美一级黄色大片| 久久精品理论片| 久久综合九色综合欧美亚洲| 国产一区二区三区四区在线观看| 久久久综合九色合综国产精品| 国产一本一道久久香蕉| 久久夜色精品国产噜噜av| 国产麻豆精品theporn| 欧美国产成人在线| 99久精品国产| 亚洲国产日韩av| 欧美精品乱码久久久久久按摩| 人人狠狠综合久久亚洲| 欧美精品一区二区在线观看| 国产成人免费av在线| 中文字幕欧美一| 欧美亚一区二区| 日韩和欧美一区二区| 精品国精品国产尤物美女| 国产精品91一区二区| 国产精品护士白丝一区av| 国产精品大尺度| 一道本成人在线| 天天影视网天天综合色在线播放| 日韩精品在线看片z| 国产精品一区二区免费不卡 | 2024国产精品| 丁香六月久久综合狠狠色| 亚洲人成7777| 欧美一区二区在线不卡| 国产成人精品亚洲午夜麻豆| 亚洲欧美日韩国产中文在线| 欧美日本视频在线| 国产成人免费视频一区| 亚洲激情校园春色| 日韩精品最新网址| www.欧美精品一二区| 亚洲成人激情自拍| 久久一二三国产| 欧美视频一区在线| 国产在线视频一区二区| 亚洲激情第一区| 26uuu久久天堂性欧美| 色偷偷久久一区二区三区| 另类小说图片综合网| 中文字幕一区在线| 日韩一区二区免费电影| 99久久久免费精品国产一区二区 | 福利一区二区在线| 午夜一区二区三区视频| 国产午夜精品一区二区三区嫩草| 91九色最新地址| 国产一区二区三区免费看| 亚洲一区二区三区三| 久久亚洲精品国产精品紫薇| 欧美伊人久久久久久久久影院| 国产精品一区二区视频| 亚洲国产成人精品视频| 国产日韩av一区二区| 欧美高清hd18日本| 色综合久久六月婷婷中文字幕| 麻豆精品视频在线| 亚洲午夜在线观看视频在线| 国产婷婷一区二区| 亚洲一二三区不卡| 中文字幕精品一区二区三区精品| 91精品福利在线一区二区三区| 91网址在线看| 高清国产一区二区三区| 日本中文字幕一区二区视频 | 国产欧美日韩视频一区二区| 欧美日韩激情在线| av不卡免费在线观看| 国产精品一区二区黑丝| 免费看日韩a级影片| 亚洲国产精品视频| 亚洲色图欧美在线| 亚洲国产精品av| 精品国产百合女同互慰| 91麻豆精品国产91久久久更新时间| 91视频在线看| 不卡av免费在线观看| 国产乱码一区二区三区| 久久综合综合久久综合| 日本sm残虐另类| 天堂午夜影视日韩欧美一区二区| 一区二区欧美视频| 亚洲精品自拍动漫在线| 成人欧美一区二区三区视频网页| 久久精品亚洲国产奇米99| 精品久久久久av影院| 欧美大黄免费观看|