本文整理汇总了C#中Heap.isEmpty方法的典型用法代码示例。如果您正苦于以下问题:C# Heap.isEmpty方法的具体用法?C# Heap.isEmpty怎么用?C# Heap.isEmpty使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Heap
的用法示例。
在下文中一共展示了Heap.isEmpty方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: MST_Prim
// Prim's algorithm to compute MST
// Code most of this yourself
int[] MST_Prim( int s)
{
int v;
int wgt = 0;
int wgt_sum = 0;
int[] dist, parent, hPos;
dist = new int[V + 1];
parent = new int[V + 1];
hPos = new int[V + 1];
Node t;
for (v = 0; v <= V; v++)
{
dist[v] = int.MaxValue;
parent[v] = 0;
hPos[v] = 0;
}
Heap pq = new Heap(V, dist, hPos);
pq.insert(s);
dist[s] = 0;
while ( ! pq.isEmpty())
{
v = pq.remove();
Console.WriteLine("Adding to MST edge {0}--({1})--{2}", toChar(parent[v]), dist[v], toChar(v));
if (v != s)
{
wgt_sum += dist[v];
}
dist[v] = 0;
for (t= adj[v]; t.data != 0; t = t.next)
{
wgt = t.wgt;
if (t.wgt < dist[t.data])
{
dist[t.data] = t.wgt;
parent[t.data] = v;
if (hPos[t.data] == 0)
{
pq.insert(t.data);
}
else
{
pq.siftUp(hPos[t.data]);
}
}
}
}
Console.Write("\n\nWeight of MST = {0}\n",wgt_sum);
return parent;
}
示例2: fillControllerEvent
public void fillControllerEvent(ControllerEventArgs args)
{
bool encontrado = false;
if(args.isLeftDown){
RaycastHit[] hits = Physics.RaycastAll(Camera.main.ScreenPointToRay(args.mousePos));
if(hits.Length>0){
Heap<float> pqHits = new Heap<float>(hits.Length);
for(int i = 0; i<hits.Length; i++){
if(hits[i].collider.transform.IsChildOf(this.transform))
pqHits.push(i+1, hits[i].distance);
}
while(!encontrado && !pqHits.isEmpty()){
RaycastHit hit = hits[pqHits.top().elem-1];
pqHits.pop();
Cell c = hit.collider.GetComponent<Cell>();
if(c!=null){
args.cell = c;
Entity[] entities = c.getEntities();
if(entities.Length==1)
fillEntity(entities[0], args);
encontrado = true;
}else{
Entity e = hit.collider.GetComponent<Entity>();
if(e!=null)
fillEntity(e,args);
encontrado=true;
}
}
}
}
args.send = args.UP || args.DOWN || args.LEFT || args.RIGHT || encontrado;
}
示例3: calculateRoute
private static Stack<Cell> calculateRoute(Cell from, Cell to, Entity entity, int distance)
{
Cell[] cells = from.Map.GetComponentsInChildren<Cell>();
Dictionary<Cell,int> cellToPos = new Dictionary<Cell, int>();
for(int i = 0; i<cells.Length; i++)
cellToPos[cells[i]] = i;
Heap<float> abierta = new Heap<float>(cells.Length);
bool[] cerrada = new bool[cells.Length];
for (int i = 0; i < cells.Length; i++)
cerrada[i] = false;
float[] f = new float[cells.Length];
float[] g = new float[cells.Length];
Cell[] anterior = new Cell[cells.Length];
for (int i = 0; i < cells.Length; i++)
anterior[i] = null;
int posInicial = cellToPos[from];
g[posInicial] = 0;
f[posInicial] = estimaMeta(from, to);
anterior[posInicial] = null;
abierta.push(posInicial + 1, f[posInicial]);
List<Cell> ends = GetSurroundCellsAtRadius(to, distance);
while (!abierta.isEmpty()){
int candidata = abierta.top().elem - 1;
abierta.pop();
Cell celdaCandidata = cells[candidata];
if (ends.Contains(celdaCandidata)){
Stack<Cell> ruta = new Stack<Cell>();
reconstruyeCamino(ruta, candidata, anterior, cells, cellToPos);
return ruta;
}
Cell[] accesibles = getCeldasAccesibles(celdaCandidata, entity);
cerrada[candidata] = true;
foreach (Cell accesible in accesibles)
{
int posAccesible = cellToPos[accesible];
float posibleG = g[candidata] + estimaAvance(celdaCandidata, accesible);
float posibleF = posibleG + estimaMeta(accesible, to);
if (cerrada[posAccesible] && posibleF >= f[posAccesible])
continue;
if (!abierta.contains(posAccesible + 1) || posibleF < f[posAccesible])
{
anterior[posAccesible] = celdaCandidata;
g[posAccesible] = posibleG;
f[posAccesible] = posibleF;
abierta.modify(posAccesible + 1, f[posAccesible]); // Modifica inserta si no esta dentro
}
}
}
return null;
}
示例4: MST_Prim
// Prim's algorithm to compute MST
// Code most of this yourself
int[] MST_Prim(int s)
{
int v;
int wgt_sum = 0;
int[] dist, parent, hPos;
Node t;
//the distance from node to node
dist = new int[V + 1];
//the parent node
parent = new int[V + 1];
//current heap position
hPos = new int[V + 1];
// initialising parent and position to zero, and dist to the max value
for (v = 1; v <= V; v++)
{
dist[v] = int.MaxValue;
parent[v] = 0;
hPos[v] = 0;
}
Heap heap = new Heap(V + 1, dist, hPos);
heap.insert(s);
dist[s] = 0;
while (!heap.isEmpty())
{
v = heap.remove();
//calculates the sum of the weights
wgt_sum += dist[v];
dist[v] = -dist[v];
Console.Write("\nAdding edge {0}--({1})--{2}", toChar(parent[v]), dist[v], toChar(v));
for (t = adj[v]; t != z; t = t.next)
{
if (t.wgt < dist[t.vert])
{
dist[t.vert] = t.wgt;
parent[t.vert] = v;
//If the vertex is empty, insert next vertex
if (hPos[t.vert] == 0)
{
heap.insert(t.vert);
}
else //Else call sift up
{
heap.siftUp(hPos[t.vert]);
}
}
}
}
Console.Write("\n\nWeight = {0}\n", wgt_sum);
return parent;
}