Exemplo n.º 1
0
        public static void WriteDoubleStackTOfile(NodeStackDMA nodeStack, string filename)
        {
            StreamWriter writer = new StreamWriter(filename, true);

            while (!nodeStack.IsEmpty)
            {
                writer.WriteLine(Convert.ToString(nodeStack.Pop()));
            }
            writer.Close();
        }
Exemplo n.º 2
0
        public static NodeStackDMA ReadDoubleStackFROMfile(string filename)
        {
            NodeStackDMA nodeStack = new NodeStackDMA();
            StreamReader reader    = new StreamReader(filename, Encoding.Default);
            string       str       = String.Empty;

            while ((str = reader.ReadLine()) != null)
            {
                nodeStack.Push(Convert.ToDouble(str));
            }
            reader.Close();
            return(nodeStack);
        }
Exemplo n.º 3
0
        public static void  DoStackTask(string readFilename, string writeFilename)
        {
            NodeStackDMA negativeStack = new NodeStackDMA();
            NodeStackDMA positiveStack = new NodeStackDMA();
            StreamReader reader        = new StreamReader(readFilename, Encoding.Default);
            string       str           = String.Empty;
            double       data;

            while ((str = reader.ReadLine()) != null)
            {
                data = Convert.ToDouble(str);
                if (data < 0)
                {
                    negativeStack.Push(data);
                }
                else
                {
                    positiveStack.Push(data);
                }
            }
            reader.Close();

            StreamWriter writer = new StreamWriter(writeFilename, true);

            while (!negativeStack.IsEmpty)
            {
                //File.AppendAllText(writeFilename, Convert.ToString(negativeStack.Pop()) + Environment.NewLine);
                writer.WriteLine(Convert.ToString(negativeStack.Pop()) + "\n");
            }
            while (!positiveStack.IsEmpty)
            {
                //File.AppendAllText(writeFilename, Convert.ToString(positiveStack.Pop()) + Environment.NewLine);
                writer.WriteLine(Convert.ToString(positiveStack.Pop()) + "\n");
            }
            writer.Close();
        }