You need to read up and understand some basics:
allocates ONE nodes instance and returns a pointer to it.
In
where did nodearr[] come from?!? Is it an automatic/local variable or dynamically allocated?
Also, by making that assignment, you've just created a memory leak because nothing points to the new nodes that you allocated on the previous line.
I think you may want something like
|
nodes *arr = &nodearr[0];
| |
without a new and delete, but I am very confused by your code.
Further down, you are calling
effectively deleting a pointer that you did not allocate (because it's not pointing to the memory that you did allocate). Not only is this very bad practice, it's at least one of the causes for your segfault.
Understand what you are trying to do before you code, or you will have a lot of problems with pointers, even if you don't segfault... I think there is a lot of confusion here.