Need help with this task [Linked Lists]

0 Cave Johnson · May 4, 2015
this is a homework ,deadline is in 24hours 
Implement a sorting algorithm for a list of points. A point is "smaller" than the other if it is closer to the origin.
The point coordinates are integers between 0 and 100.

tasks:

1. Define the structure to represent the points (class or struct).
 2. Save the related points in a linked list. The points are read from the keyboard and the user will be guided with the appropriate messages.
 3. Implement the sorting algorithm in ascending order. Points will be displayed again on the screen after sorting.
 4. Check if the points are collinear or not. A corresponding message will be displayed.
example:
     (1,1), (2,2), (3,3) Collinear or (0,1), (0,2), (0,7) Collinear
     (2, 2), (3,3), (5,2) not collinear


it's mandatory that i need to use this class file and something tells me it needs to be edited in order for it to run :
http://textuploader.com/x3u3
This is what i did so far
http://textuploader.com/x3ui
I just dont know how can i "link "a node type to a int value.Help me pls .

Post a Reply

Replies

Oldest  Newest  Rating
0 Michael Bradford · May 7, 2015
So from the first file the mandatory one, the entire node/linked list structure was made for you using Templates. I'm not sure if you've learned about that yet but basically the member called info is of type "T" (template) and will work for whatever you send it. So if you construct a node with and give info a value of 3, info will be templated to an int value and it's struct pointers will point to ints.

You don't actually have to do anything to link an int to a node type, if you set info to an int it will work as is.
0 Michael Bradford · May 7, 2015
Sorry I should have probably noted that the syntax for using a template clientside would be something like this.


LinkedList ListForUseInMainFunction();


notice the <int> that casts the Template to use ints for that object.
Also I looked at the mandatory file again and can't find a constructor/destructor which are important, so you probably do need to change that file yes, but not to use ints that's already built in.
(my apologies I only glossed over it before and noticed it was templated and therefore ints would work).
0 Michael Bradford · May 7, 2015
The code block changed my code :(, it looked like this 
LinkedList<int> ListForUseInMainFunction();
  • 1

C++

107,038 followers
About

Used in many types of software including music players, video games, and many large scale applications.

Links
Moderators
Bucky Roberts Administrator