コード例 #1
0
		public static void Main (string[] args)
		{
			//construct a cyclic sorted list
			List<Node> CyclicSortedList = new List<Node>();
			CyclicSortedList.Add(new Node(11));
			CyclicSortedList.Add(new Node(1));
			CyclicSortedList.Add(new Node(2));
			CyclicSortedList.Add(new Node(4));
			CyclicSortedList.Add(new Node(5));
			CyclicSortedList.Add(new Node(7));
			CyclicSortedList.Add(new Node(9));

			for(int i=0;i<CyclicSortedList.Count;i++)
			{
				if(i==CyclicSortedList.Count-1)
					CyclicSortedList[i].Next = CyclicSortedList[0];
				else CyclicSortedList[i].Next = CyclicSortedList[i+1];
			}

			Inserter inserter = new Inserter ();
			Node xNode = inserter.Insert (CyclicSortedList[5], 8);
			Node aNode = inserter.Insert (CyclicSortedList[5], 15);
			CyclicSortedList.Add (xNode);
			CyclicSortedList.Add (aNode);

			foreach(var node in CyclicSortedList)
			{

				Console.WriteLine(node.Value+" -> "+node.Next.Value);
			}
		}
コード例 #2
0
        public static void Main(string[] args)
        {
            //construct a cyclic sorted list
            List <Node> CyclicSortedList = new List <Node>();

            CyclicSortedList.Add(new Node(11));
            CyclicSortedList.Add(new Node(1));
            CyclicSortedList.Add(new Node(2));
            CyclicSortedList.Add(new Node(4));
            CyclicSortedList.Add(new Node(5));
            CyclicSortedList.Add(new Node(7));
            CyclicSortedList.Add(new Node(9));

            for (int i = 0; i < CyclicSortedList.Count; i++)
            {
                if (i == CyclicSortedList.Count - 1)
                {
                    CyclicSortedList[i].Next = CyclicSortedList[0];
                }
                else
                {
                    CyclicSortedList[i].Next = CyclicSortedList[i + 1];
                }
            }

            Inserter inserter = new Inserter();
            Node     xNode    = inserter.Insert(CyclicSortedList[5], 8);
            Node     aNode    = inserter.Insert(CyclicSortedList[5], 15);

            CyclicSortedList.Add(xNode);
            CyclicSortedList.Add(aNode);

            foreach (var node in CyclicSortedList)
            {
                Console.WriteLine(node.Value + " -> " + node.Next.Value);
            }
        }