the program runs without errors, but when i try to use the changenode function, if i put anything above 2 it doesn't change the correct node. here is the source code.
if for your changevalue(pos, value) function, all you want to do is change the data1 value of the node at position=pos your code should look something like this:
1 2 3 4 5 6 7 8 9 10 11
void changeNode(int pos, int value)
{
nodetype * temp; //declare a local nodetype pointer
temp = p; //set temp to the first node
int i;
for( i = 1; i < pos; i++ ) //for loop starting from 1
temp = temp->p; //iterate through list
temp->data1 = value; //temp now points to node at pos in list, change the data
}
if you are still having trouble, try working it out on paper. It is very difficult to use pointers without some careful planning. (at least in my experience) The easiest way to do this is to just draw your list and the pointers and actually do the entire changeNode(pos, value) function by hand to see EXACTLY what needs to be done.
good luck!
Actually with Standard C++ STL, I doubt we need to code our own linked list in the real business world application anymore (unless we work for employers that sell STL for a living).
For school work then it has to be done but as backprop says, pointer manipulation and algorithm implementation are best drafted on paper for easy visualization and understanding before you transform them into C++ code.
Additionally it is very unlikely that a linked list implementation that is user defined will be useful for many cases. You'll end up having to copy and paste to create specific implementations for each and every use where the STL provides something that is generic. It is also very unlikely that the creators of these implementations will have the wherewithal to have thought through all of the issues in order to provide an efficient and useful interface and implementation.