public DLinkedList(Point value, DLinkedList nxt) { data = value; next = nxt; prev = null; }
public DLinkedList() { data = new Point(0, 0); next = null; prev = null; }
public static DLinkedList[] polygonIntermsofLinkedLIst() { Console.WriteLine("---------------------------------------"); Console.WriteLine("Enter the number of Points in polygon: "); Console.WriteLine("---------------------------------------"); int numberofnode = Convert.ToInt32(Console.ReadLine()); Point[] pointofPolygon = new Point[numberofnode]; for (int i = 0; i < numberofnode; i++) { Console.WriteLine("-----------------"); Console.WriteLine("Enter the Point: "); Console.WriteLine("-----------------"); string Input = Console.ReadLine(); string[] Number = Input.Split(',', ' '); pointofPolygon[i] = new Point(Convert.ToInt32(Number[0]), Convert.ToInt32(Number[1])); } DLinkedList[] nonode = new DLinkedList[numberofnode]; nonode[0] = new DLinkedList(pointofPolygon[0]); for (int i = 1; i < numberofnode; i++) { nonode[i] = nonode[i - 1].InsertPrevNext(pointofPolygon[i]); } nonode[0] = nonode[numberofnode - 1].InsertPrevNext(pointofPolygon[0], nonode[0].next); return(nonode); }
public static DLinkedList[] polygonIntermsofLinkedLIst() { Console.WriteLine("------------------------------------------------------"); Console.WriteLine("To Construct the polygon, enter the number of Points:"); Console.WriteLine("------------------------------------------------------"); int numberofnode = Convert.ToInt32(Console.ReadLine()); Point[] pointofPolygon = new Point[numberofnode]; for (int i = 0; i < numberofnode; i++) { Console.WriteLine("-----------------"); Console.WriteLine("Enter the Point: "); Console.WriteLine("-----------------"); string Input = Console.ReadLine(); string[] Number = Input.Split(',', ' '); pointofPolygon[i] = new Point(Convert.ToInt32(Number[0]), Convert.ToInt32(Number[1])); } // Non convex polygon pointofPolygon = pointofPolygon.OrderBy(x => x.y).ToArray(); if (pointofPolygon[0].y == pointofPolygon[1].y) { if (pointofPolygon[1].x > pointofPolygon[0].x) { Point temp = pointofPolygon[0]; for (int i = 1; i < numberofnode; i++) { pointofPolygon[i - 1] = pointofPolygon[i]; } pointofPolygon[numberofnode - 1] = temp; } else { Point temptobePlacedAtbeginning = pointofPolygon[0]; Point temptobePlacedAtend = pointofPolygon[1]; for (int i = 2; i < numberofnode; i++) { pointofPolygon[i - 1] = pointofPolygon[i]; } pointofPolygon[0] = temptobePlacedAtbeginning; pointofPolygon[numberofnode - 1] = temptobePlacedAtend; } } pointofPolygon = arrangepointsforpolygon(pointofPolygon); Console.WriteLine("The Polygon is formed in the order:"); foreach (var item in pointofPolygon) { Console.WriteLine("***************"); Console.WriteLine(item.x + "," + item.y); } //*********************************** DLinkedList[] nonode = new DLinkedList[numberofnode]; nonode[0] = new DLinkedList(pointofPolygon[0]); for (int i = 1; i < numberofnode; i++) { nonode[i] = nonode[i - 1].InsertPrevNext(pointofPolygon[i]); } nonode[0] = nonode[numberofnode - 1].InsertPrevNext(pointofPolygon[0], nonode[0].next); return(nonode); }
//DLinkedList method is used for inserting only next and previous other than last.next and first.prev element public DLinkedList InsertPrevNext(Point value, DLinkedList nxt) { DLinkedList node = new DLinkedList(value, nxt); node.prev = this; this.next = node; return(node); }
//InsertPrevNext method is used for inserting next and previous other than last.next element public DLinkedList InsertPrevNext(Point value) { DLinkedList node = new DLinkedList(value); if (this.next == null) { node.prev = this; this.next = node; } return(node); }
public DLinkedList(Point value) { data = value; next = null; prev = null; }