I am trying to insert elements on to a heap with the code below but get error "conversion to double from struct not possible"
ElementsToInsert = [];ElementsToInsert(1).pos = [3,1]; ElementsToInsert(1).key = 4; ElementsToInsert(2).pos = [3,2]; ElementsToInsert(2).key = 2; ElementsToInsert(3).pos = [3,3]; ElementsToInsert(3).key = 1; ElementsToInsert(4).pos = [4,2]; ElementsToInsert(4).key = 3;BinMinHeap = [];for n=1:1:length(ElementsToInsert) %insert ElementsToInsert(n) at the end of the heap
BinMinHeap(n)=ElementsToInsert(n)while BinMinHeap(n)<=BinMinHeap(n-1) swap(BinMinHeap(n),BinMinHeap(n-1)) %BinMinHeap(n)=BinMinHeap(n-1)
...; end end
Best Answer