Getting a grasp on Binary Heaps

So I’ve been reading this article on binary heaps and trying to incorporate it in my pathfinding code but have no luck. I was hoping to get some feedback on my attempt to see what went wrong:

	void SortedAdd (Node nextNode) {

		if(open.Count < 1){
			open.Add(new Node());
			return;
		}

		open.Add(nextNode);

		int index = open.IndexOf(nextNode);
		int parentIndex = Mathf.RoundToInt(index/2);
		float fCost = nextNode.f;

		while(fCost > open[parentIndex].f){
			if(fCost > open[parentIndex].f){
				Swap(nextNode, open[parentIndex]);
				int opIndex = parentIndex;
				parentIndex = Mathf.RoundToInt(opIndex/2);
			}else{
				break;
			}
		}
	}

	void Swap (Node n1, Node n2) {

		int n1ind = open.IndexOf(n1);
		int n2ind = open.IndexOf(n2);
		open[n1ind] = n2;
		open[n2ind] = n1;
	}

When I checked the open list, the nodes were not in order therefore the path was all over the place. Any idea where I went wrong?

Are you trying to sort a List <> by fCost? maybe this will help you c# - How to Sort a List<T> by a property in the object - Stack Overflow

Is there a library I’m supposed to be using? Because List<> doesn’t contain OrderBy() or OrderByDescending().

If you want to use binary heaps, you need “sink down”, “bubble up”, “and get-from-heap”(pop) style functions, so you can interact with it.
and when using heaps, once you get something from the heap, it’s no longer on the heap, so be sure it’s what you need

this is pretty clear
http://eloquentjavascript.net/appendix2.html

you dont need any special libraries, except collections.generic