Example #1
0
        static void Main(string[] args)
        {
            LinkList <String> test_NT_NC = new LinkList <String>(false, false);
            LinkList <String> test_NT_C  = new LinkList <String>(false, true);
            LinkList <String> test_T_NC  = new LinkList <String>(true, false);
            LinkList <String> test_T_C   = new LinkList <String>(true, true);

            //插入测试1
            for (Int32 i = 1; i <= 6; i++)
            {
                test_NT_NC.InsectNode(i, i.ToString());
                test_NT_C.InsectNode(i, i.ToString());
                test_T_NC.InsectNode(i, i.ToString());
                test_T_C.InsectNode(i, i.ToString());
            }
            //输出
            display(test_NT_NC, "test_NT_NC");
            display(test_NT_C, "test_NT_C");
            display(test_T_NC, "test_T_NC");
            display(test_T_C, "test_T_C");
            Console.ReadLine();
            Console.Clear();

            //删除测试
            for (Int32 i = 1; i <= 10; i++)
            {
                test_NT_NC.DeleteNode(1);
                test_NT_C.DeleteNode(1);
                test_T_NC.DeleteNode(1);
                test_T_C.DeleteNode(1);
            }
            //输出
            display(test_NT_NC, "test_NT_NC");
            display(test_NT_C, "test_NT_C");
            display(test_T_NC, "test_T_NC");
            display(test_T_C, "test_T_C");
            Console.ReadLine();
            Console.Clear();

            //插入测试2
            for (Int32 i = 1; i <= 20; i++)
            {
                test_NT_NC.InsectNode(i, i.ToString());
                test_NT_C.InsectNode(i, i.ToString());
                test_T_NC.InsectNode(i, i.ToString());
                test_T_C.InsectNode(i, i.ToString());
            }
            //输出
            display(test_NT_NC, "test_NT_NC");
            display(test_NT_C, "test_NT_C");
            display(test_T_NC, "test_T_NC");
            display(test_T_C, "test_T_C");
            Console.ReadLine();
            Console.Clear();

            //搜索测试
            Int32 loc = 0;

            display(test_NT_NC, "test_NT_NC");
            for (Int32 i = 1; i <= 12; i++)
            {
                Console.Out.WriteLine("查找数据:" + i);
                test_NT_NC.SearchNode(ref loc, i.ToString());
                Console.Out.WriteLine("位置信息:" + loc);
                Console.Out.WriteLine();
            }
            Console.ReadLine();
            Console.Clear();
            display(test_NT_C, "test_NT_C");
            for (Int32 i = 1; i <= 12; i++)
            {
                Console.Out.WriteLine("查找数据:" + i);
                test_NT_C.SearchNode(ref loc, i.ToString());
                Console.Out.WriteLine("位置信息:" + loc);
                Console.Out.WriteLine();
            }
            Console.ReadLine();
            Console.Clear();
            display(test_T_NC, "test_T_NC");
            for (Int32 i = 1; i <= 12; i++)
            {
                Console.Out.WriteLine("查找数据:" + i);
                test_T_NC.SearchNode(ref loc, i.ToString());
                Console.Out.WriteLine("位置信息:" + loc);
                Console.Out.WriteLine();
            }
            Console.ReadLine();
            Console.Clear();
            display(test_T_C, "test_T_C");
            for (Int32 i = 1; i <= 12; i++)
            {
                Console.Out.WriteLine("查找数据:" + i);
                test_T_C.SearchNode(ref loc, i.ToString());
                Console.Out.WriteLine("位置信息:" + loc);
                Console.Out.WriteLine();
            }
            Console.ReadLine();
            Console.Clear();

            //GetNextValue测试
            String val = "\u0000";

            display(test_NT_NC, "test_NT_NC");
            for (Int32 i = 1; i <= 12; i++)
            {
                Console.Out.Write(test_NT_NC.GetNextValue(ref val) + "   ");
                Console.Out.WriteLine(val);
                val = null;
            }
            test_NT_NC.ResetPointer();
            Console.ReadLine();
            Console.Clear();
            display(test_NT_C, "test_NT_C");
            for (Int32 i = 1; i <= 12; i++)
            {
                Console.Out.Write(test_NT_C.GetNextValue(ref val) + "   ");
                Console.Out.WriteLine(val);
                val = null;
            }
            test_NT_C.ResetPointer();
            Console.ReadLine();
            Console.Clear();
            display(test_T_NC, "test_T_NC");
            for (Int32 i = 1; i <= 12; i++)
            {
                Console.Out.Write(test_T_NC.GetNextValue(ref val) + "   ");
                Console.Out.WriteLine(val);
                val = null;
            }
            test_T_NC.ResetPointer();
            Console.ReadLine();
            Console.Clear();
            display(test_T_C, "test_T_C");
            for (Int32 i = 1; i <= 12; i++)
            {
                Console.Out.Write(test_T_C.GetNextValue(ref val) + "   ");
                Console.Out.WriteLine(val);
                val = null;
            }
            test_T_C.ResetPointer();
            Console.ReadLine();
            Console.Clear();

            //清空测试
            test_NT_NC.ClearAll();
            test_NT_C.ClearAll();
            test_T_NC.ClearAll();
            test_T_C.ClearAll();
            //输出
            display(test_NT_NC, "test_NT_NC");
            display(test_NT_C, "test_NT_C");
            display(test_T_NC, "test_T_NC");
            display(test_T_C, "test_T_C");
            Console.ReadLine();
            Console.Clear();

            //结束
            Console.Out.WriteLine("测试结束!");
            Console.Out.WriteLine();
            Console.Out.WriteLine("按任意键退出...");
            Console.ReadLine();
        }
Example #2
0
 //绘出链表demo当前状态下的图形
 private void Draw()
 {
     if (_demo != null)
     {
         Int32  temp_i1;
         Int32  temp_i2;
         String temp_s = null;
         //专用指针复位
         _demo.ResetPointer();
         //绘图:头节点
         labelOutputHead.Visible = true;
         //如果demo不是空的
         if (_demo.GetIsEmpty() == false)
         {
             //绘图:值框
             for (temp_i1 = 1; (temp_i2 = _demo.GetNextValue(ref temp_s)) != 0; temp_i1++)
             {
                 labelOutput[temp_i1].Text = temp_s;
                 if (temp_i2 == 2)
                 {
                     break;
                 }
             }
             //绘图:箭头
             for (temp_i2 = 1; temp_i2 <= temp_i1; temp_i2++)
             {
                 labelOutput[temp_i2].Visible    = true;
                 pictureBoxNext[temp_i2].Visible = true;
                 if (_demo.GetIsTwoWay())
                 {
                     pictureBoxLast[temp_i2].Visible = true;
                 }
             }
             //绘图:如果是循环链表,绘出与头节点有关Next和Last的箭头
             if (_demo.GetIsCircle())
             {
                 //基准点设置
                 Int32 basePointX = pictureBoxNextCircle.Location.X;
                 Int32 basePointY = pictureBoxNextCircle.Location.Y;
                 //平移值和间隔值设定
                 Int32 moveValue     = 22;
                 Int32 intervalValue = 34;
                 //定位黑色顶点
                 Point blackTail = new Point(basePointX + 11, basePointY - 5 + 57 * temp_i1);
                 Point blackM1   = new Point(basePointX + 11 + moveValue, basePointY - 5 + 57 * temp_i1);
                 Point blackM2   = new Point(basePointX + 11 + moveValue, basePointY - 5 + 57 * temp_i1);
                 Point blackM3   = new Point(basePointX + 11 + moveValue, basePointY + 8);
                 Point blackM4   = new Point(basePointX + 11 + moveValue, basePointY + 8);
                 Point blackHead = new Point(basePointX + 11, basePointY + 8);
                 //微调黑色顶点
                 blackM2.X -= 2;
                 blackM3.X -= 2;
                 //绘出黑色的折线
                 _graph.DrawLine(_blackPen, blackTail, blackM1);
                 _graph.DrawLine(_blackPen, blackM2, blackM3);
                 _graph.DrawLine(_blackPen, blackM4, blackHead);
                 //绘出黑色箭头
                 pictureBoxNextCircle.Visible = true;
                 //如果是双向链表,绘出图头节点有关的Last箭头
                 if (_demo.GetIsTwoWay())
                 {
                     //定位灰色顶点
                     Point grayTail = new Point(basePointX + 11, basePointY - 5);
                     Point grayM1   = new Point(basePointX + 11 + moveValue + intervalValue, basePointY - 5);
                     Point grayM2   = new Point(basePointX + 11 + moveValue + intervalValue, basePointY - 5);
                     Point grayM3   = new Point(basePointX + 11 + moveValue + intervalValue, basePointY + 8 + 57 * temp_i1);
                     Point grayM4   = new Point(basePointX + 11 + moveValue + intervalValue, basePointY + 8 + 57 * temp_i1);
                     Point grayHead = new Point(basePointX + 11, basePointY + 8 + 57 * temp_i1);
                     //微调灰色顶点
                     grayM2.X -= 2;
                     grayM3.X -= 2;
                     //绘出灰色的折线
                     _graph.DrawLine(_grayPen, grayTail, grayM1);
                     _graph.DrawLine(_grayPen, grayM2, grayM3);
                     _graph.DrawLine(_grayPen, grayM4, grayHead);
                     //绘出灰色箭头
                     pictureBoxLastCircle[temp_i1].Visible = true;
                 }
             }
         }
         //如果demo是空的
         else
         {
             //绘图:如果是循环链表,绘出循环链表空标志
             if (_demo.GetIsCircle())
             {
                 pictureBox_NextCircleEmpty.Visible = true;
                 if (_demo.GetIsTwoWay())
                 {
                     pictureBox_LastCircleEmpty.Visible = true;
                 }
             }
         }
     }
     else
     {
         ResetAll();
     }
 }