Esempio n. 1
0
        /// <summary>
        /// Finds the Kth node from end of a Linked List
        /// </summary>
        /// <param name="k">The target value</param>
        /// <param name="ll">A Linked List</param>
        /// <returns>Returns the value at the searched for node</returns>
        public static object NodeFinderAtK(int k, LL ll)
        {
            int counter = 0;

            ll.Current = ll.Head;
            while (ll.Current != null)
            {
                counter++;
                ll.Current = ll.Current.Next;
            }
            ll.Current = ll.Head;
            try
            {
                if (k > counter)
                {
                    throw new Exception("Value is outside Linked List");
                }
            }
            catch (Exception e)
            {
                return(e.Message);
            }

            for (int i = 0; i < counter - k; i++)
            {
                ll.Current = ll.Current.Next;
            }
            return(ll.Current.Value);
        }
Esempio n. 2
0
 private void button2_Click(object sender, EventArgs e)
 {
     SetDay   = int.Parse(textBox3.Text);
     SetDay_K = double.Parse(textBox4.Text);
     SetDay_D = double.Parse(textBox5.Text);
     KL.Add(SetDay_K);
     DL.Add(SetDay_D);
     for (int i = SetDay; i < HL.Count; i++)
     {
         var    h   = HL.GetRange(i - SetDay, SetDay + 1).ToList();
         var    l   = LL.GetRange(i - SetDay, SetDay + 1).ToList();
         var    v   = VL.GetRange(i - SetDay, SetDay + 1).ToList();
         double max = h.Max();
         double min = l.Min();
         double RSV = ((v.Last() - min) / (max - min)) * 100d;
         double k   = ((2d / 3d) * KL.Last()) + ((1d / 3d) * RSV);
         double d   = ((2d / 3d) * DL.Last()) + ((1d / 3d) * k);
         KL.Add(k);
         DL.Add(d);
     }
     using (StreamWriter sw = new StreamWriter(textBox2.Text))
     {
         for (int i = 0; i < KL.Count; i++)
         {
             sw.Write(KL[i].ToString("0.00") + " ");
         }
         sw.WriteLine("");
         for (int i = 0; i < KL.Count; i++)
         {
             sw.Write(DL[i].ToString("0.00") + " ");
         }
         sw.WriteLine("");
     }
     Process.Start(textBox2.Text);
 }
Esempio n. 3
0
        public void CanMergeLinkedListSecondListLonger()
        {
            Node LL1Node1 = new Node("LL1Node1");
            Node LL1Node2 = new Node("LL1Node2");
            Node LL1Node3 = new Node("LL1Node3");
            Node LL1Node4 = new Node("LL1Node4");
            Node LL1Node5 = new Node("LL1Node5");

            Node LL2Node1 = new Node("LL2Node1");
            Node LL2Node2 = new Node("LL2Node2");
            Node LL2Node3 = new Node("LL2Node3");
            Node LL2Node4 = new Node("LL2Node4");
            Node LL2Node5 = new Node("LL2Node5");
            Node LL2Node6 = new Node("LL2Node6");

            LL LL1 = new LL(LL1Node1);
            LL LL2 = new LL(LL2Node1);

            LL1.Append(LL1Node2);
            LL1.Append(LL1Node3);
            LL1.Append(LL1Node4);
            LL1.Append(LL1Node5);

            LL2.Append(LL2Node2);
            LL2.Append(LL2Node3);
            LL2.Append(LL2Node4);
            LL2.Append(LL2Node5);
            LL2.Append(LL2Node6);

            LLMerge(LL1, LL2);

            Assert.NotEqual(LL1Node3, LL1Node2.Next);
        }
Esempio n. 4
0
        static void Main(string[] args)
        {
            /// List ist eine generische Klasse, wird so programmiert, dass man hineinspeichern kann, was man möchte
            /// z.B. int, string, float,...
            List <int> list = new List <int>();

            list.Add(5);
            list.Add(-3);
            Program[] abc = new Program[10];
            abc[0].machEtwas();

            // myTry
            List <object> test = new List <object>();

            test.Add(2.3);
            test.Add("hallo");
            test.Add(list[0]);

            List <string> sList = new List <string>();

            sList.Add("Hallo");
            sList.Add("Welt");

            MeinContainer <int, string> mc = new MeinContainer <int, string>(5, "Zahl");

            mc.print();
            MeinContainer <double, int> mc2 = new MeinContainer <double, int>(3.3, 5);

            mc2.print();

            //Stack: First In, Last Out (FILO)
            //Queue: First In, First Out (FIFO)
            MeinStack <int> s = new MeinStack <int>();

            // Push: zum Stack hinzufügen (drauflegen); Pop: vom Stack (von oben) entfernen; Peek: oberstes Element des Stacks anzeigen
            s.Push(5);
            s.Push(7);
            s.Push(-4);
            s.Push(9);
            Console.WriteLine(s.Peek()); //9
            Console.WriteLine(s.Pop());  //9
            Console.WriteLine(s.Pop());  //-4
            Console.WriteLine(s.Peek()); //7

            LL <int> LL = new LL <int>(1);

            LL.AddAtEnd(2);
            LL.AddAtEnd(3);
            LL.AddAtEnd(4);
            LL.AddAtEnd(5);
            LL.AddAtEnd(6);
            LL.AddAtEnd(7);
            LL.PrintList();
            LL.InsertAfterIndex(100, 2);
            LL.PrintList();
            Console.ReadKey();
            LL.RemoveIndex(3);
            LL.PrintList();
            Console.ReadKey();
        }
Esempio n. 5
0
        public static void RemoveSpecificDuplicateTest()
        {
            LL  head = new LL(8);
            int d    = 88;

            RemoveSpecificDuplicate(head, d);
        }
Esempio n. 6
0
        public static int FindKthFromEnd(LL head, int k)
        {
            int LengthOfLL = 0;
            int response   = 0;
            LL  n          = head;

            while (n.next != null)
            {
                LengthOfLL++;
                n = n.next;
            }
            int countFromStart = LengthOfLL - k;
            int counter        = 0;

            Console.WriteLine(countFromStart);

            while (head.next != null)
            {
                if (counter == countFromStart)
                {
                    Console.WriteLine(head.data);
                    break;
                }
                counter++;
                head = head.next;
            }


            return(response);
        }
Esempio n. 7
0
        public static (LL <Instr>, Env <Arg>, int) AssignHomes(LL <Instr> instrs, LL <string> vars)
        {
            var env = AssignStackLocations(vars, RBP, -8, 8);
            int cnt = env.size;

            return(AssignHomes(env, instrs), env, cnt);
        }
Esempio n. 8
0
        public static (Program, Set <string>) AllocateRegisters(Program program, LL <string> locals, LL <Arg> registers)
        {
            LL <(Block block, Set <string> locals)> lives = GetLocals(program);
            //Log.Info($"Live Detection: {lives}");
            Set <string> stillLive     = new Set <string>(locals);
            int          mainLocals    = -1;
            Set <Arg>    mainRegisters = null;

            LL <Block> modifiedBlocks = lives.Map((it) => {
                //Log.Info($"Modifying: {it.block}\nLive Set {it.locals}");
                Graph <Arg> graph = Interference(it.block.instructions);
                //Log.Info($"Got graph: {graph.ToString(true)}");
                LL <(string name, int?id)> coloring = ColorGraph(graph, it.locals);
                //Log.Info($"Got coloring: {coloring}");
                LL <string> names = coloring.Map(it => it.name);

                Env <Arg> mappings  = AssignRegisters(coloring, registers);
                stillLive          -= mappings.KeySet;
                LL <Instr> modified = AllocateRegisters(it.block.instructions, mappings);

                (LL <Instr> modified2, var env, var locals) = AssignHomes(modified, names);
                if (it.block.label == "start")
                {
                    mainLocals    = (it.locals - mappings.KeySet).Count;
                    mainRegisters = mappings.ValueSet;
                }
                return(new Block(modified2, it.block.label));
            });

            var prelude     = Prelude(mainLocals, mainRegisters);
            var conclusion  = Conclusion(mainLocals, mainRegisters);
            var fullProgram = new LL <Block>(prelude, new LL <Block>(conclusion, modifiedBlocks));

            return(new Program(fullProgram), stillLive);
        }
        /// <summary>
        /// Gets an audio description for auditory output for a polygon point.
        /// </summary>
        /// <param name="pointsObs">The points observer.</param>
        /// <returns>a string suitable for auditory output.</returns>
        public static string GetPointAudio(OoPolygonPointsObserver pointsObs)
        {
            if (pointsObs != null)
            {
                int index;
                var point = pointsObs.Current(out index);
                if (!point.Equals(default(PolyPointDescriptor)))
                {
                    index += 1;
                    string nodeType = LL.GetTrans("tangram.oomanipulation.element_speaker.label." + point.Flag.ToString());

                    // remove one point from count if first and last point is equal
                    int count = pointsObs.Count - (pointsObs.FirstPointEqualsLastPoint() ? 1 : 0);

                    String audio = LL.GetTrans("tangram.oomanipulation.element_speaker.audio.point",
                                               nodeType,
                                               index,
                                               count
                                               );

                    return(audio);
                }
            }
            return(String.Empty);
        }
        /// <summary>
        /// Creats a group object
        /// </summary>
        /// <returns>The Shape observer for the newly created group or <c>null</c>.</returns>
        private OoShapeObserver createGroup()
        {
            OoShapeObserver group = null;

            OoAccessibleDocWnd  draw = null;
            OoDrawPagesObserver doc  = null;
            OoDrawPageObserver  page = null;

            if (IsShapeSelected && LastSelectedShape != null)
            {
                page = LastSelectedShape.Page;
                doc  = page.PagesObserver;
                draw = doc.DocWnd;
            }
            else
            {
                // TODO: how to get those things
            }

            if (doc != null && draw != null && draw.DrawPageSupplier != null)
            {
                Logger.Instance.Log(LogPriority.DEBUG, this, "[NOTICE]\t[DRAWING]\t[CREATE]\t" + "build group shape");
                var grpShape = OoDrawUtils.CreateGroupShape_anonymous(draw.DrawPageSupplier);
                OoUtils.SetStringProperty(grpShape, "Name", LL.GetTrans("tangram.oomanipulation.shape.group"));
                if (page != null && page.DrawPage_anonymouse != null)
                {
                    var pageObj = page.DrawPage_anonymouse;
                    OoDrawUtils.AddShapeToDrawPageUndoable(grpShape, pageObj, draw.DrawPageSupplier);
                    group = doc.RegisterNewShape(grpShape);
                }
            }

            return(group);
        }
Esempio n. 11
0
        public static void FindKthFromEndTest()
        {
            LL  head = new LL(8);
            int d    = 88;

            FindKthFromEnd(head, d);
        }
        public void NotAPalindromeTest()
        {
            Node node1 = new Node("S");
            Node node2 = new Node("H");
            Node node3 = new Node("A");
            Node node4 = new Node("I");
            Node node5 = new Node("H");
            Node node6 = new Node("U");
            Node node7 = new Node("L");
            Node node8 = new Node("U");
            Node node9 = new Node("D");

            LL LL1 = new LL(node1);

            LL1.Append(node2);
            LL1.Append(node3);
            LL1.Append(node4);
            LL1.Append(node5);
            LL1.Append(node6);
            LL1.Append(node7);
            LL1.Append(node8);
            LL1.Append(node9);

            Assert.False(PalindromeChecker(LL1));
        }
Esempio n. 13
0
        private void WriteOutput(string text, LL logLevel, LL fileLL)
        {
            {
                string output = System.DateTime.Now.ToString()
                                + " : " + new StackFrame(2).GetMethod().Module
                                + " : " + new StackFrame(2).GetMethod().Name;

                output = output + "[" + GetLLText(logLevel) + "]: " + text;


                string date = System.DateTime.Now.Year.ToString() + "." +
                              System.DateTime.Now.Month.ToString() + "." +
                              System.DateTime.Now.Day.ToString() + " " +
                              System.DateTime.Now.Hour.ToString() + "_00_00";

                string fullPath1 = AppDomain.CurrentDomain.BaseDirectory;
                if (!Directory.Exists(fullPath1 + "log"))
                {
                    Directory.CreateDirectory(fullPath1 + "log");
                }

                string filenameLoglevel = fullPath1 + "log\\" + date + " " + fileLL.ToString() + ".txt";

                using (StreamWriter sw = File.AppendText(filenameLoglevel))
                {
                    sw.WriteLine(output);
                }
            }
        }
        /// <summary>
        /// Checks to see if a linked list is a palindrome
        /// </summary>
        /// <param name="LL">Takes a Linked List</param>
        /// <returns>Returns a true if the linked list is a palindrome otherwise returns false</returns>
        public static bool PalindromeChecker(LL LL)
        {
            LL.Current = LL.Head;
            bool isPalindrome = true;
            int  counter      = 0;

            while (LL.Current != null)
            {
                counter++;
                LL.Current = LL.Current.Next;
            }
            string[] letters = new string[counter];
            LL.Current = LL.Head;
            int i = 0;

            while (LL.Current != null)
            {
                letters[i] = LL.Current.Value.ToString();
                i++;
                LL.Current = LL.Current.Next;
            }
            for (i = 0; i < letters.Length / 2; i++)
            {
                if (letters[i] != letters[letters.Length - 1 - i])
                {
                    isPalindrome = false;
                }
            }
            return(isPalindrome);
        }
        /// <summary>
        /// Gets a compressed textual description for Braille text output for a polygon point.
        /// </summary>
        /// <param name="pointsObs">The points observer.</param>
        /// <returns>a string suitable for short Braille output.</returns>
        public static string GetPointText(OoPolygonPointsObserver pointsObs)
        {
            if (pointsObs != null)
            {
                int index;
                var point = pointsObs.Current(out index);
                if (!point.Equals(default(PolyPointDescriptor)))
                {
                    index += 1;
                    string nodeType = LL.GetTrans("tangram.oomanipulation.element_speaker.label." + point.Flag.ToString());

                    // remove one point from count if first and last point is equal
                    int count = pointsObs.Count - (pointsObs.FirstPointEqualsLastPoint() ? 1 : 0);

                    String text = LL.GetTrans("tangram.oomanipulation.element_speaker.text.point",
                                              nodeType,
                                              index,
                                              count,
                                              (((float)point.X / 1000f)).ToString("0.##cm"),
                                              (((float)point.Y / 1000f)).ToString("0.##cm")
                                              );

                    //point.Flag.ToString() + " (" + index + "/" + pointsObs.Count + ") - x:" + point.X + " y:" + point.Y;

                    return(text);
                }
            }
            return(String.Empty);
        }
Esempio n. 16
0
    public List <uint> CrabGameCustomLinkedList(List <uint> numbers, ulong numMoves)
    {
        LL  cups           = new LL(numbers);
        var currentNode    = cups.Head;
        var smallestNumber = numbers.Min();

        for (ulong move = 0; move < numMoves; move++)
        {
            // remove the following 3 values after the current node.
            var pickupNodes = new List <LLNode <uint> >(3);
            for (int i = 0; i < 3; ++i)
            {
                // remove head
                if (currentNode.Next == null)
                {
                    pickupNodes.Add(cups.RemoveHead());
                }
                else
                {
                    pickupNodes.Add(cups.RemoveNext(currentNode));
                }
            }

            // find the destination node, nearest smallest node from the current value.
            LLNode <uint> destinationNode = null;
            for (uint destinationValue = currentNode.Value - 1; destinationValue >= smallestNumber; destinationValue--)
            {
                var lookupNode = cups.Lookup[(int)destinationValue];
                if (lookupNode != null)
                {
                    destinationNode = lookupNode;
                    break;
                }
            }

            // if the above algorithm does not find a value, select the greatest value.
            destinationNode ??= cups.Lookup.Last(x => x != null);

            // Add the nodes after the destination node.
            for (int i = 0; i < 3; i++)
            {
                var nodeToAdd = pickupNodes[i];
                cups.AddAfterNode(destinationNode, nodeToAdd);
                destinationNode = nodeToAdd;
            }
            currentNode = currentNode.Next ?? cups.Head;
        }

        // create a list of values from the linkedlist, with the retained order.
        var node   = cups.Head;
        var result = new List <uint>();

        do
        {
            result.Add(node.Value);
            node = node.Next;
        }while (node != null);
        return(result);
    }
Esempio n. 17
0
 public static Env <Arg> AssignStackLocations(LL <string> vars, Register reg, int offset, int size)
 {
     if (vars == null)
     {
         return(new Env <Arg>());
     }
     return(AssignStackLocations(vars.next, reg, offset - size, size).Extend(vars.data, new Arg(reg, offset)));
 }
Esempio n. 18
0
 public static LL <(Block, Set <string>)> GetLocals(LL <Block> blocks)
 {
     if (blocks == null)
     {
         return(null);
     }
     return(GetLocals(blocks.next).Add((blocks.data, GetLocals(blocks.data))));
 }
Esempio n. 19
0
        public void LLIntilizationUserString()
        {
            string expected = "ll=";
            LL     LL       = new LL("UserString");

            expected += "UserString";
            Assert.AreEqual(expected, LL.GetPartUrl());
        }
Esempio n. 20
0
        private int ApplyDict(int index)
        {
            var dictStart = Math.Max(index - Mem.K64, 0);
            var dictSize  = index - dictStart;

            LL.LZ4_setStreamDecode(_context, _outputBuffer + dictStart, dictSize);
            return(index);
        }
Esempio n. 21
0
        public void Print_First_Node_Without_Content()
        {
            // Arrange
            LL test_list = new LL();

            // Act
            test_list.printFirstNode();
        }
Esempio n. 22
0
 public static void Write(string text, LL logLevel)
 {
     if (instance == null)
     {
         instance = new MessageHandler();
     }
     instance.WriteLN(text, logLevel);
 }
Esempio n. 23
0
 public static LL <Instr> PatchBlock(LL <Instr> block)
 {
     if (block == null)
     {
         return(null);
     }
     return(PatchInstr(block.data) + PatchBlock(block.next));
 }
Esempio n. 24
0
        public void Add_New_Node_With_No_Content()
        {
            // Arrange
            int data      = 1;
            LL  test_list = new LL();

            // Act
            test_list.Add(data);
        }
Esempio n. 25
0
        public StartScreen(LL ll, int width, int height) : base("StartScreen")
        {
            this.ll = ll;

            title = new BrailleIOViewRange(2, 2, width - 4, height - 4);
            title.SetText(ll.GetTrans("game.title") + "\n" + ll.GetTrans("game.keybindings1") + "\n" + ll.GetTrans("game.keybindings2") + "\n" + ll.GetTrans("game.keybindings3") + "\n" + ll.GetTrans("game.keybindings4"));

            AddViewRange(title);
        }
Esempio n. 26
0
        /// <summary>
        /// Initializes the localization framework with a translation file.
        /// </summary>
        private void initLL()
        {
            // Load an XML file contain the different translations.
            // You can load a file from a path or a file delivered through the project resources.
            ll = new LL(Properties.Resources.language);

            // use this by calling the function:
            // ll.GetTrans(String key, params string[] strs)
        }
Esempio n. 27
0
        internal static SaveGame LoadSaveGame(string saveGame, LL ll)
        {
            XmlDocument doc = new XmlDocument();

            doc.Load("../../Resources/" + saveGame + ".xml");

            SaveGame save = saveGameFromDocument(ll, doc);

            return(save);
        }
 private void jumpToTopBorder(BrailleIOViewRange center)
 {
     if (center != null)
     {
         center.SetYOffset(0);
         io.RefreshDisplay();
         audioRenderer.PlaySoundImmediately(LL.GetTrans("tangram.lector.wm.panning.jump.up"));
         Logger.Instance.Log(LogPriority.MIDDLE, this, "[INTERACTION] jump to top");
     }
 }
Esempio n. 29
0
        public static LL <Instr> AssignHomes(Env <Arg> env, LL <Instr> block)
        {
            if (block == null)
            {
                return(null);
            }
            var instrs = AssignHomes(env, block.next);

            return(instrs.Add(AssignHome(env, block.data)));
        }
Esempio n. 30
0
        internal static SaveGame CreateNewGame(LL ll)
        {
            XmlDocument doc = new XmlDocument();

            doc.Load("Resources/game_state_new.xml");

            SaveGame save = saveGameFromDocument(ll, doc);

            return(save);
        }
Esempio n. 31
0
 public static bool TryParseLL(object text, out object result)
 {
     result = null;
     if (text is string == false || string.IsNullOrEmpty((string)text)) return false;
     var split = ((string)text).Trim().Split(' ');
     double xx, yy;
     if (!(split.Length == 2
         && double.TryParse(split[0].Trim(), NumberStyles.Float, CultureInfo.InvariantCulture, out xx)
         && double.TryParse(split[1].Trim(), NumberStyles.Float, CultureInfo.InvariantCulture, out yy)))
         return false;
     try {
         result = new LL(xx, yy);
         return true;
     } catch { }
     return false;
 }
Esempio n. 32
0
 public double Distance(LL to)
 {
     double er = 6366.707;
     double latFrom = Deg2rad(this.Latitude);
     double latTo = Deg2rad(to.Latitude);
     double lngFrom = Deg2rad(this.Longitude);
     double lngTo = Deg2rad(to.Longitude);
     double x1 = er * Math.Cos(lngFrom) * Math.Sin(latFrom);
     double y1 = er * Math.Sin(lngFrom) * Math.Sin(latFrom);
     double z1 = er * Math.Cos(latFrom);
     double x2 = er * Math.Cos(lngTo) * Math.Sin(latTo);
     double y2 = er * Math.Sin(lngTo) * Math.Sin(latTo);
     double z2 = er * Math.Cos(latTo);
     return Math.Sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2) + (z1 - z2) * (z1 - z2));
 }