static void MySingleLinkedListTest() { MySingleLinkedList <int> linkedList = new MySingleLinkedList <int>(); // Test1:顺序插入4个节点 linkedList.Add(0); linkedList.Add(1); linkedList.Add(2); linkedList.Add(3); Console.WriteLine("The nodes in the linkedList:"); for (int i = 0; i < linkedList.Count; i++) { Console.WriteLine(linkedList[i]); } Console.WriteLine("----------------------------"); // Test2.1:在索引为0(即第1个节点)的位置插入单个节点 linkedList.Insert(0, 10); Console.WriteLine("After insert 10 in index of 0:"); for (int i = 0; i < linkedList.Count; i++) { Console.WriteLine(linkedList[i]); } // Test2.2:在索引为2(即第3个节点)的位置插入单个节点 linkedList.Insert(2, 20); Console.WriteLine("After insert 20 in index of 2:"); for (int i = 0; i < linkedList.Count; i++) { Console.WriteLine(linkedList[i]); } // Test2.3:在索引为5(即最后一个节点)的位置插入单个节点 linkedList.Insert(5, 30); Console.WriteLine("After insert 30 in index of 5:"); for (int i = 0; i < linkedList.Count; i++) { Console.WriteLine(linkedList[i]); } Console.WriteLine("----------------------------"); // Test3.1:移除索引为5(即最后一个节点)的节点 linkedList.RemoveAt(5); Console.WriteLine("After remove an node in index of 5:"); for (int i = 0; i < linkedList.Count; i++) { Console.WriteLine(linkedList[i]); } // Test3.2:移除索引为0(即第一个节点)的节点 linkedList.RemoveAt(0); Console.WriteLine("After remove an node in index of 0:"); for (int i = 0; i < linkedList.Count; i++) { Console.WriteLine(linkedList[i]); } // Test3.3:移除索引为2(即第三个节点)的节点 linkedList.RemoveAt(2); Console.WriteLine("After remove an node in index of 2:"); for (int i = 0; i < linkedList.Count; i++) { Console.WriteLine(linkedList[i]); } Console.WriteLine("----------------------------"); }
public void OpenDay() { WaitQueueLength = 0; //等待队列长度初始化为0 Number_event = 0; //事件数设为0 for (int i = 1; i < 4; i++) { income[i] = Number_Customer[i] = Number_Staff[i] = 0; } ev = new MySingleLinkedList <Event>(); //初始化事件链表 en.Select = 0; //顾客的理发师级别; TotalTime = 0; //顾客逗留时间初始化为0 CustomerNum = 0; //顾客总数初始化为0 en.OccurTime = rd.Next(0, 601); //设置第一个客户到达事件 en.ArriveTime = en.OccurTime; en.NType = 0; if (en.ArriveTime < CloseTime)//如果第一个顾客的到达时间小于关店时间则加入时间链表 { ev.Add(en); } else { FactCloseTime = StartTime.AddSeconds(CloseTime);//如果没有第一个顾客则记录实际关店时间 } text.Text = ""; onecustumer.Text = (Number_Customer[1]).ToString(); twocustumer.Text = (Number_Customer[2]).ToString(); threecustumer.Text = (Number_Customer[3]).ToString(); Number_Staff[1] = Convert.ToInt32(text3.Text); Number_Staff[2] = Convert.ToInt32(text4.Text); Number_Staff[3] = Convert.ToInt32(text5.Text); int maxn = 0; for (int i = 1; i <= 3; i++) { if (Number_Staff[i] > maxn) { maxn = Number_Staff[i]; } } TheLeaveTimeOfFirstCustomer_Queue = new int[4, maxn + 1]; for (int i = 1; i <= 3; i++) { for (int j = 1; j <= maxn; j++) { TheLeaveTimeOfFirstCustomer_Queue[i, j] = 0; } } QStaff1 = new MyLinkQueue <CustomerNode> [Number_Staff[1]]; for (int i = 0; i < Number_Staff[1]; i++) { QStaff1[i] = new MyLinkQueue <CustomerNode>(); } QStaff2 = new MyLinkQueue <CustomerNode> [Number_Staff[2]]; for (int i = 0; i < Number_Staff[2]; i++) { QStaff2[i] = new MyLinkQueue <CustomerNode>(); } QStaff3 = new MyLinkQueue <CustomerNode> [Number_Staff[3]]; for (int i = 0; i < Number_Staff[3]; i++) { QStaff3[i] = new MyLinkQueue <CustomerNode>(); } }