I have a trivial resize function that just doubles array size when original list is full. From what I see, C++ treats unset indices as "empty" with values of 0. After I declared new double-sized array and copied elems from old list, I tried to output it in main but once it goes past last index w/ an item, it starts printing weird values, rather than 0's to indicate unset indices. The old and new lists are respectively: hashtable_1, hashtable_2.
The code is very trivial. Please let me know.
Code:
#include <iostream>
using namespace std;
//Note: trivial resize...I think there's a better one yet
void resize_v1(int* old_list, int* new_list, int size)//Note: new list will be declared in main
{
for ( int i = 0; i < size; ++i )
new_list[i] = old_list[i];
}
int main()
{
int hashtable_1[15] = {0,0,9,0,1000,44,19,201,666,444,57,88,88908,77,33};
int size_1 = sizeof(hashtable_1)/sizeof(int);//this is capacity, NOT num elems in list so far
int hashtable_2[30] = {};
cout << "Empty slot: " << hashtable_2[29] << endl;//I'm talking about this line, why does it output 0, yet in the for-loop below, it
outputs: -1 etc
int size_2 = sizeof(hashtable_2)/sizeof(int);
resize_v1(&hashtable_1[0], &hashtable_2[0], size_2);
cout << size_2 << endl;
for ( int i = 0; i < size_2; ++i )//weird values outputted once its past 15th index (last index that's occupied from old list: hashtable_1
{
cout << "cur i: " << i << endl;
cout << hashtable_2[i] << " , " << endl << endl;
}
cout << endl;
return 0;
}