public void Fun_Permute_Queue(int n, int m) { CQueue <int> m_cqueue = new CQueue <int>(); int[] zijishulie = new int[n]; for (int i = 0; i < n; i++) { zijishulie[i] = i + 1; } int i1 = 0; while (i1 < n) { while (m_cqueue.Rear() - m_cqueue.Front() < m && i1 < n) { m_cqueue.In(zijishulie[i1]); i1++; } for (int j = 0; j < m; j++) { int[] k1 = new int[m]; for (int i = 0; i < m; i++) { k1[i] = i1 - m + i + 1; } int count = 0; int[,] k2 = new int[1000, 10]; for (int i = 0; i < m; i++) { k2[count, i] = i1 - m + i + 1; } for (int j1 = j + 1; j1 < m; j1++) { for (int j2 = 0; j2 <= count; j2++) { int count1 = 0; int[] k3 = new int[10]; for (int i12 = 0; i12 < m; i12++) { k3[i12] = k2[j2, i12]; } swap(k3, j, j1); for (int i13 = 0; i13 < m; i13++) { k2[count1++, i13] = k3[i13]; } for (int i = 0; i < m; i++) { m_strout += Convert.ToString(k3[i]); } m_strout += "\r\n"; count = count1; } } } m_cqueue.Out(); } }
public string ShortPath() //最短路径 { move[0].x = 0; move[0].y = +1; move[1].x = +1; move[1].y = +1; move[2].x = +1; move[2].y = 0; move[3].x = +1; move[3].y = -1; move[4].x = 0; move[4].y = -1; move[5].x = -1; move[5].y = -1; move[6].x = -1; move[6].y = 0; move[7].x = -1; move[7].y = +1; //初始化位置坐标增量 sq = new CQueue <sqtype>(); //创建队列 if (rows == 0 || cols == 0) { return(""); } sqtype temp = new sqtype(); temp.x = temp.y = 1; temp.pre = 0; sq.In(temp); Setelems(1, 1, -1); //起点进队 while (!sq.IsEmpty()) //队不空时循环 { temp = sq.Getfront(); int x = temp.x; int y = temp.y; //取队头 for (int k = 0; k < 8; k += 2) //查找八个方向 { int i = x + move[k].x; int j = y + move[k].y; if (Getelems(i, j) == 0) //路通 { temp.x = i; temp.y = j; temp.pre = sq.Front() + 1; //前一个结点 sq.In(temp); //进队 Setelems(i, j, -1); //走过的设置为-1 } if (i == rows && j == cols) { int j1 = sq.Rear(); int len = 0; for (int i1 = sq.Rear(); i1 >= 1; i1--) { temp = sq.Getdata(i1); if (i1 == j1) { Setelems(temp.x, temp.y, -1); j1 = temp.pre; len++; } else { Setelems(temp.x, temp.y, 0); } } return(""); } } sq.Out(); //出队 } return(""); }