Ejemplo n.º 1
0
        public void Delete(string value)
        {
            NODE current      = Head;
            NODE tempPrevious = null;

            if (IsEmpty() == true)
            {
                Console.WriteLine("LINKEDLIST IS EMPTY");
            }

            else
            {
                if (Head.data == value)
                {
                    Head = Head.next;
                }

                else
                {
                    while (current != null)
                    {
                        if (current.data == value)
                        {
                            tempPrevious.next = current.next;
                            current           = null;
                        }
                        else
                        {
                            tempPrevious = current;
                            current      = current.next;
                        }
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public int Length()
        {
            int  i       = 0;
            NODE current = Head;

            while (current != null)
            {
                current = current.next;
                i++;
            }
            return(i);
        }
Ejemplo n.º 3
0
        public void deleteAll()
        {
            NODE current      = Head;
            NODE tempPrevious = null;

            while (current != null)
            {
                tempPrevious = current.next;

                current = null;
            }
            Head = null;
        }
Ejemplo n.º 4
0
        public void Insert(string value)
        {
            NODE newNode = new NODE(value);

            if (Head == null)
            {
                Head = newNode;
            }
            else
            {
                NODE current = Head;
                while (current.next != null)
                {
                    current = current.next;
                }
                current.next = newNode;
            }
        }
Ejemplo n.º 5
0
        public string Get(int index)
        {
            NODE current = Head;
            int  count   = 0;

            while (current != null)
            {
                if (count == index)
                {
                    return(current.data);
                }
                count++;
                current = current.next;
            }


            return(null);
        }
Ejemplo n.º 6
0
        public string Search(string value)
        {
            NODE temp  = Head;              //Temporary node to traverse
            bool state = false;

            while (temp != null)
            {
                if (temp.data == value)
                {
                    state = true;
                    return(temp.data);
                }
                else
                {
                    temp = temp.next;
                }
            }

            if (state == false)
            {
                // Console.WriteLine("Value Not Found");
            }
            return("-999");
        }
Ejemplo n.º 7
0
 public LinkedList_()
 {
     Head = null;
 }
Ejemplo n.º 8
0
 public NODE(string item)
 {
     this.data = item;
     this.next = null;
 }