I have a heap insert function in c++
Void insert(int n){
Size++;
Array[size]= n;
//percolateup
}
Void insert(int n){
Array[size+1]= n:
Size++;
//percolateup
}
Among the above two codes, are they both mean same or different logic?
-> 1st approach- incremented size and then inserted.
-> 2nd approach- increased array size by one and inserted and incremented.
Which one correct?
Please help me..
Yes, both snippets change the program state in equivalent ways.