| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 531 人关注过本帖
标题:【请教】用顺序栈解决火车车厢重排问题的编程中缺少using指令的错误
只看楼主 加入收藏
℡﹏聽雨"
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2011-4-14
结帖率:0
收藏
 问题点数:0 回复次数:0 
【请教】用顺序栈解决火车车厢重排问题的编程中缺少using指令的错误
C#
运行程序时错误(找不到类型或命名空间名称“LinkStack”(是否缺少using指令或程序集引用))
用顺序栈解决火车车厢重排问题的编程中,运行时有个错误,说明写道:(找不到类型或命名空间名称“LinkStack”(是否缺少using指令或程序集引用))
应该是缺少using指令吧?但是不知道应该用什么指令,希望高手们帮帮忙~~

源代码:
using System;
using System.Collections.Generic;
using System.Text;

namespace 实验三
{
    class Program
    {
        static void Main(string[] args)
        {

            int[] p = new int[] { 3, 6, 9, 2, 4, 7, 1, 8, 5 };
            int k = 3;
            TrainArrangeByLinkStack ta = new TrainArrangeByLinkStack();
            bool result;
            result = ta.Railroad(p, p.Length, k);
            do
            {
                if (result == false)
                {
                    Console.Write("need more holding track,please enter additional number:");
                    k = k + Convert.ToInt32(Console.ReadLine());
                    result = ta.Railroad(p, p.Length, k);
                }
            }
            while (result == false);
            Console.ReadLine();

        }

        class TrainArrangeByLinkStack
        {
            //k个缓冲铁轨,车厢初始排序存储在p中
            bool Railroad(int[] p, int n, int k)
            {
                //如果重排成功,返回true,否则返回false
                //创建与缓冲铁轨对应的堆栈
                LinkStack<int>[] H;
                H = new LinkStack<int>[k + 1];
                for (int i = 1; i <= k; i++)
                    H[i] = new LinkStack<int>();
                int NowOut = 1;//下一次要输出的车厢
                int minH = n + 1;//缓冲铁轨中编号最小的车厢
                int minS = 0;//minH号车厢对应的缓冲铁轨
                //车厢重排
                for (int i = 1; i < n; i++)
                    if (p[i] == NowOut)
                    {
                        ConSole.WriteLine("Move Car{0}from input to output", p[i]);
                        NowOut++;
                        //从缓冲铁轨中输出
                        while (minH == nowOut)
                        {
                            Output(ref minH, ref minS, ref H, k, n);
                            NowOut++;

                        }
                    }
                    else
                    {//将p[i]送入某个缓冲铁轨
                        if (!Hold(p[i], ref minH, ref minS, ref H, k, n))
                            return false;
                    }
                return true;
            }
            //把车厢从缓冲铁轨送至出轨处,同时修改minS和minH
            void Output(ref int minH, ref int minS, ref LinkStack<int>[] H, int k, int n)
            {
                int c;  //从堆栈minS中删除编号最小的车厢minH
                c = H[minS].Pop();
                Console.WriteLine("Move Car{0}from holding track {1} to output", minH, minS);
                minH = n + 2;
                for (int i = 1; i <= k; i++)
                    if (!H[i].IsEmpty() && (c = H[i].Top.Data) < minH)
                    {
                        minH = c;
                        minS = i;
                    }
            }
            //在一个缓冲铁轨中放入车厢c
            bool Hold(int c, ref int minH, ref int minS, ref LinkStack<int>[] H, int k, int n)
            {
                //如果没有可用的缓冲铁轨,则返回false
                //否则返回true
                //为车厢c寻找最优的换成铁轨
                //初始化
                int BestTrack = 0;//目前最优的铁轨
                int BestTop = n + 1;//最优铁轨上的头辆车厢
                int x;//车厢索引
                //扫描缓冲铁轨
                for (int i = 1; i <= k; i++)
                    if (!H[i].IsEmpty())
                    {//铁轨i顶部的车厢编号最小
                        x = H[i].Top.Data;
                        if (c < x && x < BestTop)
                        {
                            BestTop = x;
                            BestTrack = i;
                        }
                    }
                    else   //铁轨i为空
                    {
                        if (BestTrack == 0) bestTrack = i;
                        break;
                    }
                if (BestTrack == 0)
                    return false;    //没有可用的铁轨
                //把车厢c送入缓冲铁轨
                H[BestTrack].Push(c);
                Console.WriteLine("Move Car{0}from input to holding track{1}", c, BestTrack);
                //必要时修改min和HminS
                if (c < minH)
                {
                    minH = c; minS = BestTrack;
                }
                return true;
            }
            //调用火车车厢重排算法Railroad()重排车厢
        }



    }


}
 

[ 本帖最后由 ℡﹏聽雨" 于 2011-4-14 18:30 编辑 ]
搜索更多相关主题的帖子: 空间名称 源代码 火车 
2011-04-14 18:22
快速回复:【请教】用顺序栈解决火车车厢重排问题的编程中缺少using指令的错误
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.042304 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved