Esempio n. 1
0
        /// <summary>
        /// Gets the data at a specified index
        /// </summary>
        public string GetData(int index)
        {
            if (index < 0 || index >= count)
            {
                throw new IndexOutOfRangeException();
            }
            else
            {
                CustomLinkedNode current = head;
                for (int i = 0; i < index; i++)
                {
                    current = current.Next;
                }

                return(current.Data);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Adds a string to the end of the list
        /// </summary>
        public void Add(string data)
        {
            if (count == 0)
            {
                head = new CustomLinkedNode(data);
            }
            else
            {
                CustomLinkedNode current = head;
                for (int i = 0; i < count - 1; i++)
                {
                    current = current.Next;
                }

                current.Next = new CustomLinkedNode(data);
            }

            count++;
        }
Esempio n. 3
0
 public CustomLinkedNode(string data)
 {
     this.data = data;
     next      = null;
 }
Esempio n. 4
0
 public CustomLinkedList()
 {
     head  = null;
     count = 0;
 }