Solved

Can someone with more coding experience, try re-wording this so I understand it better, dumb it down.

Posted on 2008-06-15
7
207 Views
Last Modified: 2010-04-01
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.
0
Comment
Question by:jschmuff
  • 3
  • 2
  • 2
7 Comments
 
LVL 53

Expert Comment

by:Infinity08
ID: 21789876
Which part is it that you don't understand ? Linked lists are a common data structure, consisting of nodes linked together by pointers. Take a look at this wiki for a very good overview :

        http://en.wikipedia.org/wiki/Linked_list
0
 

Author Comment

by:jschmuff
ID: 21789887
Ok ill ask a few questions here:
I need to take in two different int and create a different one to ask the user how many he will input? or will I take x and the value of the int and y will be the amount the user wants to input?

 I am really confused on what is wanted here. If someone can dumb this down for me that would be great I have a text book here with the linked list problem there are no real examples in it that show output. So I am confused on the whole matter.
0
 
LVL 53

Accepted Solution

by:
Infinity08 earned 500 total points
ID: 21789920
A point is a combination of two values : x and y. These two values represent the X and Y coordinates of the point. You'll have to create a struct called Point that contains an x and y value.

Then you'll have to create a linked list that holds these Point structs as elements. See the wiki I posted earlier to get a better idea of what a linked list is, how it works, and how to implement it properly.

Finally, you'll have to have an input loop, asking the user in each iteration to enter a new point (two values, x and y). This point is then added to the linked list (ordered by the x value).

When the user decides that he has entered enough points, you simply iterate through the linked list, and show all points in it.
0
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 19

Expert Comment

by:LordOfPorts
ID: 21789930
The assignment does not specify how to identify the number of points the user wishes to enter so this part is up to you, you can for example ask the user how many points they wish to create as the first question and then loop that many times collecting the integer pairs that compose a point or you can have a loop that will go on until the user hits enter without having specified the 2 integers, so it would be e.g.:

while the read input is not the just the "Enter" key
ask for integer X
ask for integer Y
construct a new point out of the 2 integers
insert the new point object as a node into the linked list in ascending order
end while
loop through the linked list and display the values
0
 

Author Comment

by:jschmuff
ID: 21789977
So kind of like this then except I need to now display them?


#include <iostream>
 
using namespace std;
 
int main()
{
	struct Point
	{
		int x;
		int y;
		Point *next;
	};
 
	Point *head = NULL;
 
	int count = 0;
	int Xx;
	int Yy;
 
	cout << "How many integers to enter for each x and y: ";
	cin >> count;
	cout << endl;
 
	for (int i = 0; i < count; i++)
	{
		cout << "Enter int X: ";
		cin >> Xx;
		cout << endl;
		cout << "Enter int Y: ";
		cin >> Yy;
		cout << endl;
 
		Point *temp1 = new Point;
		temp1->x = Xx;
 
		temp1->next = head;
		head = temp1;
 
		Point *temp2 = new Point;
		temp2->y = Yy;
 
		temp2->next = head;
		head = temp2;
 
	}
}

Open in new window

0
 
LVL 19

Expert Comment

by:LordOfPorts
ID: 21790017
You do not need to construct temp2, assign the Xx and Yy to x and y of temp1 respectively. Also one of your requirements is to insert the point into the linked list in ascending order by value of x, currently you are just adding the new point to the beginning of the list when instead you have to traverse the list check the value of x of each node in the list and then insert the new point at the appropriate place so the items are in order.
0
 
LVL 53

Expert Comment

by:Infinity08
ID: 21790911
what LordOfPorts said ^ ;)
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Unable to start eclipse ? 17 154
C# code editing and collaboration 3 137
C++ mouse_event mouse look 7 99
Work with App store 7 71
How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question