Hello, could some please help me with a current project that I'm working on for school? I have the following code, but the output shows unknown address. The following is the description of my assignment, and the code I have so far. Thank you.
Write a program that creates a linked list of points. For this Assignment we define a point as a set of integers, X and Y. This linked list should insert the points ordered by the x value. The user is prompted to enter as many points as they desire. Each point is a new node in the linked list. After the user has entered all the points they wish to enter, the program is to output the linked list data (i.e. X and Y integers) as it appears in the linked list.
#include <iostream>
#include <list>
#include <cassert>
#include <ostream>
using namespace std;
struct node
{
node *info;
node *link;
int x, y;
};
int main()
{
node *first, *last, *newNode;
int input;
cout << "Enter the interger for x and y value" << endl;
first = NULL;
last = NULL;
do
{
//x integers
cout << "Input X value or -999 to stop: ";
cin >> input;//read info
int x = input; //store info (x) into input
newNode = new node();//allocate memory for the type node
assert(newNode != NULL);//terminate program is no memory space
newNode->x = input;//copy value into input
newNode->link = NULL;
if (first == NULL)
{
first = newNode;
last = newNode;
}
else
{
last->link = newNode;
last = newNode;
}
//y integers
cout << "Input Y value or -999 to stop: ";
cin >> input;//get info
int y = input;//store in for (y) into input
newNode = new node;//allocate memory for the type node
assert(newNode != NULL);//terminate program is no memory space
newNode->y = input;//copy value into input
//newNode->link = input;
newNode->link = NULL;
if (first == NULL)
{
first = newNode;
last = newNode;
}//end if
else
{
last->link = newNode;
last = newNode;
}//end else
}//end do
while (input != -999);
newNode = first;
while (newNode != NULL)
{
//cout << "(" << newNode ->x << "," << newNode ->y << ")" <<endl;
// Test output
cout << newNode ->x << endl;
cout << newNode ->y << endl;
newNode = newNode->link;
}
system ("pause");
}