Exemplo n.º 1
0
    public static LLClass RemoveDuplicatesFromLinkedList(LLClass linkedList)
    {
        LLClass temp = linkedList;

        //Console.WriteLine(temp.PrintList());
        while (temp.Next != null)
        {
            while (temp.Next != null && temp.Value == temp.Next.Value)
            {
                if (temp.Next.Next != null)
                {
                    temp.Next = temp.Next.Next;
                }
                else
                {
                    temp.Next = null;
                }
            }
            if (temp.Next != null)
            {
                temp = temp.Next;
            }
        }
        return(linkedList);
    }
Exemplo n.º 2
0
    public void Add(int value)
    {
        LLClass root = this;

        while (root.Next != null)
        {
            root = root.Next;
        }
        root.Next = new LLClass(value);
    }
Exemplo n.º 3
0
    public string PrintList()
    {
        string  output = "";
        LLClass node   = this;

        while (node.Next != null)
        {
            output += $"{node.Value} - ";
            node    = node.Next;
        }
        output += node.Value;
        return(output);
    }
Exemplo n.º 4
0
    static void Main(string[] args)
    {
        var test = new LLClass(1);

        test.Add(1);
        test.Add(1);
        test.Add(3);
        test.Add(4);
        test.Add(4);
        test.Add(4);
        test.Add(5);
        test.Add(6);
        test.Add(6);
        Console.WriteLine(test.PrintList());
        Console.WriteLine(RemoveDuplicatesFromLinkedList(test).PrintList());
    }
Exemplo n.º 5
0
 public LLClass(int value)
 {
     Value = value;
     Next  = null;
 }