Esempio n. 1
0
        void PlaceinTheList(Mochila x)
        {
            if (x.Position().Equals(0))
            {
                listBox1.Items.Clear();
            }
            if (x.Next() != null)
            {
                if (x.Previous() != null)
                {
                    listBox1.Items.Add(x.Position() + ": Mochila " + x.Index() + " e dentro tem a " +
                                       x.Next().Index() +
                                       " e está dentro da " + x.Previous().Index());
                }
                else
                {
                    listBox1.Items.Add(x.Position() + ": Mochila " + x.Index() + " e dentro tem a " +
                                       x.Next().Index() + " e não está dentro de nenhuma");
                }

                PlaceinTheList(x.Next());
            }
            else
            {
                if (x.Previous() != null)
                {
                    listBox1.Items.Add(x.Position() + ": Mochila " + x.Index() + " e dentro tem nada e está dentro da " + x.Previous().Index());
                }
                else
                {
                    listBox1.Items.Add(x.Position() + ": Mochila " + x.Index() + " e dentro tem nada e não está dentro de nenhuma");
                }
                textBox4.Text = (x.Position() + 1).ToString();
            }
        }
Esempio n. 2
0
 void GoToIndex(Mochila x, int index)
 {
     if (x.Previous().Index() != index)
     {
         ChangePosition(x, x.Previous());
         GoToIndex(x.Previous(), index);
     }
 }
Esempio n. 3
0
 void GoToPosition(Mochila x, int position)
 {
     if (x.Position() != position)
     {
         ChangePosition(x, x.Previous());
         GoToPosition(x.Previous(), position);
     }
 }
Esempio n. 4
0
        void AllBackToPosition(Mochila x, int first)
        {
            if (x.Next() != null)
            {
                if (first.Equals(0))
                {
                    if (x.Previous() != null)
                    {
                        x.Previous().Next(x.Next());
                        x.Next().Previous(x.Previous());
                        x.Next().Position(x.Position());
                    }
                    else
                    {
                        m = x.Next();
                        m.Previous(null);
                        m.Position(0);
                        m.Next().Position(1);
                    }
                }
                else
                {
                    x.Next().Position(x.Position() + 1);
                }

                AllBackToPosition(x.Next(), first + 1);
            }
            else if (first.Equals(0))
            {
                if (x.Previous() != null)
                {
                    x.Previous().Next(null);
                }
                else
                {
                    x = new Mochila();
                }
            }
        }