Hey guys, I'm trying to learn/understand linked lists so I wrote this program just to see if I could do it, and to try and understand the process better etc. It compiles fine but when I read it I get memory access violation errors and stuff. Could someone please tell me what's going on. Basically I just wanted it to print 1-29 or whatever, and it would create 30 structure nodes, and each printed digit would be from each seperate node. Here is the code!
Code:
#include <iostream>
int main()
{
int i = 0;
struct node {
int x;
node *next;
};
node *root;
node *conductor;
root = new node;
root->x = i;
root->next = new node;
conductor = root->next;
if (conductor != 0)
{
while (conductor != 0 && i < 30)
{
conductor->x = i++;
std::cout<<conductor->x;
conductor = conductor->next;
}
}
std::cin.get();
return 0;
}