GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — KAlgorithm/Disjointset.h at master · Tracy02022/KAlgorithm Expand file tree/ Copy pathDisjointset.hMore file actions 56 lines (54 loc) · 863 Bytes / Copy pathDisjointset.hFile metadata and controls56 lines (54 loc) · 863 Bytes 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 //Dongyu Li #pragma once #include<vector> using namespace std; class Disjointset { private: int num; vector<int> vec; public: Disjointset():num(0){} Disjointset(int numElement) { num=numElement; } int find(int); bool unionSet(int,int); void Initialize(int ); int getNumber()const; }; void Disjointset::Initialize(int n) { num=n; for(int i=0;i<n;i++) { vec.push_back(-1); } } //given two roots of two sets, joins them to set bool Disjointset::unionSet(int elem1,int elem2) { int root1=find(elem1); int root2=find(elem2); if(root1==root2) return false ; else { vec[root2]=root1; return true; } } //return the root of the set int Disjointset::find(int element) { if(vec[element]==-1) return element; else return find(vec[element]); } //return the total number of vertices int Disjointset::getNumber() const { return num; } |
| You are visitor 01402792 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |