I want to have a linked list, with a variable which has dynamic size,
because I want to just allocate different sizes for a variable in different nodes.
for example node1 has a array variable with size 1, but node 2 has a array variable with size 10, and node3 never allocates this array.
like this:
struct st{
int * var_dynamic;
int x;
};
now I want to initialize them. for the static one, it is like this:
struct st st1;
st1.x=1;
but how can I initialize the dynamic one?
Is it something like this?
st1.var_dynamic= new int [100];
and if yes, Is this way correct and efficient?
st1.array[1]=1;You didn't mention anarrayvariable. Also, have you heard ofstd::vector?std::vector? It was designed to be efficient and error free.std::list. Or you want an array? Then you wantstd::vector. Or do you want to implement a data structure yourself?