so i have this problem. I have to create triangles out of dots and find the perimeter of the triangle using linkedLists when given two text files.
In one text file there is information about the dots: Its color, its X coordinate and Y coordinate. The file looks like this:
Red,5,7
Blue,6,5
Red,2,4
Blue,3,0
Red,0,0
Blue,0,5
Yellow,1,4
Brown,5,6
Yellow,2,3
Yellow,1,1
In the other text file is information given about the color and if you are able to create a triangle out of it:
Red,Yes
Yellow,Yes
Brown,No
Yellow,Yes
I have created a node class and MyList class for each respectively.
public class Colors
{
public string Color { get; set; }
public int X { get; set; }
public int Y { get; set; }
public Colors(string spalva, int x, int y)
{
Color = spalva;
X = x;
Y = y;
}
public override string ToString()
{
string eilute;
eilute = String.Format("{0, -15} {1, -20} {2, -20}", Color, X, Y);
return eilute;
}
}
}
public sealed class Node
{
public Colors DuomTask { get; set; }
public Node Kitas { get; set; }
public Node(Colors task, Node adr)
{
DuomTask = task;
Kitas = adr;
}
}
class MyList
{
private Node pr;
private Node pb;
private Node d;
public MyList()
{
this.pr = null;
this.pb = null;
this.d = null;
}
public Colors ImtiDuom()
{
return d.DuomTask;
}
public Node GetFirst()
{
return pr;
}
public Node GetLast()
{
return pb;
}
public void DetiDuomenis(Colors naujas)
{
var dd = new Node(naujas, null);
if(pr != null)
{
pb.Kitas = dd;
pb = dd;
}
else
{
pr = dd;
pb = dd;
}
What i am attempting to do:
I am trying to figure out if you can create a triangle out of a given color. If you can i want to save that data so that i could find the perimeter of the triangles.
What i already tried:
static void CanYouFormTriangle(MyList Dots, MyList2 Info)
{
MyList Triangle = new MyList();
for(Node d = Dots.GetFirst(); d != null; d = d.Kitas)
{
for(Node2 j = Info.GetFirst(); j != null; j = j.Kitas)
{
if (d.DuomTask.Color == j.InfoDot.Color && j.InfoDot.Able == "Yes")
{
Console.WriteLine("Color: {0, -5} Coordinates: {1, -2} {2}",d.DuomTask.Color, d.DuomTask.X, d.DuomTask.Y);
Triangle = Dots;
}
}
}
Console.WriteLine("=============");
for (Node d = Triangle.GetFirst(); d != null; d = d.Kitas)
{
Console.WriteLine("Color: {0, -5} Coordinates: {1, -2} {2}", d.DuomTask.Color, d.DuomTask.X, d.DuomTask.Y);
}
}
}
When i print the data inside the IF statement the output appears to be correct, but when i add the data to my newly created MyList class and try to print it, the output is incorrect because the color Brown appears and i can't make a triangle out of that.
Color: Red Coordinates: 5 7
Color: Blue Coordinates: 6 5
Color: Red Coordinates: 2 4
Color: Blue Coordinates: 3 0
Color: Red Coordinates: 0 0
Color: Blue Coordinates: 0 5
Color: Yellow Coordinates: 1 4
Color: Yellow Coordinates: 2 3
Color: Yellow Coordinates: 1 1
=============
Color: Red Coordinates: 5 7
Color: Blue Coordinates: 6 5
Color: Red Coordinates: 2 4
Color: Blue Coordinates: 3 0
Color: Red Coordinates: 0 0
Color: Blue Coordinates: 0 5
Color: Yellow Coordinates: 1 4
Color: Brown Coordinates: 5 6
Color: Yellow Coordinates: 2 3
Color: Yellow Coordinates: 1 1
Press any key to continue . . .
Aucun commentaire:
Enregistrer un commentaire