Hi guys. For some reason I cannot get the linked list to print. I want to copy it(which works) but I cannot get the list to print after copying it. Any suggestions?
#include <iostream>
using namespace std;
struct node
{
int info;
node* next;
};
int main()
{
node* list;
list = new node;
list->next = NULL;
node* curr = list;
list->info = 0;
int num = 1;
while(num <= 100)
{
node* temp = new node;
if (temp == NULL)
{
cout << "Error. No memory was allocated.";
break;
}
temp->info = num;
curr->next = temp;
curr = curr->next;
num++;
}
curr = list;
while(curr != NULL)//print linked list
{
cout << "node: " << curr->info;
cout << endl;
curr = curr->next;
}
cout << "Copying Linked List";
//copy linked list
while(curr != NULL)
{
node* copy = new node;
copy->info = curr->info;
copy->next = NULL;
curr = curr->next;
}
cout << "The list was copied.";
copy = curr;
while(copy != NULL)//print copied linked list
{
cout << "node: " << copy->info;
cout << endl;
copy = copy->next;
}
return 0;
}