Exemplo n.º 1
0
        //TOSTRING()

        public override string ToString()
        {
            NodeClass Current_Node = Head;

            int Index = Count;

            string FinalString = "";

            while (Index > 0)
            {
                Current_Node = Head;

                for (int i = 0; i <= Index - 1; i++)
                {
                    if (Current_Node.Next != null)
                    {
                        Current_Node = Current_Node.Next;
                    }
                    else
                    {
                        Current_Node = Tail;
                    } //end if
                }     //end for
                FinalString += Current_Node.Data.ToString();
                FinalString += "\n";
                Index--;
            }//end while

            return(FinalString);
        } //end tostring()
Exemplo n.º 2
0
        }//end clear method

        //create 1 string for list
        public override string ToString()
        {
            NodeClass Current_Node = Head;
            string    FinalString  = "[";

            while (Current_Node != null)
            {
                if (Current_Node.Data is string || Current_Node.Data is char)
                {
                    FinalString += "\"";
                    FinalString += Current_Node.Data;
                    FinalString += "\"";
                }
                else
                {
                    FinalString += Current_Node.Data;
                }

                if (Current_Node.Next != null)
                {
                    FinalString += ", ";
                }
                else
                {
                    FinalString += "]";
                }

                Current_Node = Current_Node.Next;
            }//end while

            return(FinalString);
        }//end to string
Exemplo n.º 3
0
        }//end indexof method

        //remove entry at specific index
        public void Remove(int SearchDat)
        {
            // delete by index

            NodeClass CurrentNode = Head;
            NodeClass Swap        = null;
            int       Runs        = 0;

            if (SearchDat == 0)
            {
                Head = Head.Next;
                Count--;
            }
            else if (SearchDat == Count)
            {
                while (CurrentNode.Next != null)
                {
                    if (Runs == Count - 1)
                    {
                        Swap             = CurrentNode.Next;
                        CurrentNode.Next = CurrentNode.Next.Next;
                        Swap             = null;
                        Count--;
                        return;
                    }
                    else
                    {
                        CurrentNode = CurrentNode.Next;
                        Runs++;
                    }
                }//end while
            }
            else if (SearchDat < 0 || SearchDat > Count)
            {
                throw new Exception("Index outside of bounds!");
            }

            while (CurrentNode.Next != null)
            {
                if (Runs == SearchDat - 1)
                {
                    Swap             = CurrentNode.Next;
                    CurrentNode.Next = CurrentNode.Next.Next;
                    Swap             = null;
                    Count--;
                    return;
                }
                else
                {
                    CurrentNode = CurrentNode.Next;
                    Runs++;
                }
            }
        }//end remove method
Exemplo n.º 4
0
        }//end indexor

        //SetNodeBIndex
        public void SetNodeByIndex(int index, object NewData)
        {
            int       CurrentIndex = 0;
            NodeClass CurrentNode  = Head;

            while (CurrentNode != null)
            {
                if (CurrentIndex == index)
                {
                    CurrentNode.Data = NewData;
                    return;
                }
            }
            throw new Exception("Object not found.");
        }
Exemplo n.º 5
0
        //Getnodebyindex
        private object GetNodeByIndex(int SearchIndex)
        {
            int       CurrentIndex = 0;
            NodeClass CurrentNode  = Head;

            while (CurrentNode != null)
            {
                if (SearchIndex == CurrentIndex)
                {
                    return(CurrentNode.Data);
                }
                CurrentNode = CurrentNode.Next;
                CurrentIndex++;
            } //end while
            throw new Exception("Index not found.");
        }     //end nodebyindex
Exemplo n.º 6
0
        //PUSH()

        public void Push(object New_Dat)
        {
            NodeClass New_Node = new NodeClass(New_Dat);

            Empty = false;

            if (Head == null)
            {
                Head = New_Node;
                Tail = New_Node;
            }
            else
            {
                Head.Next = New_Node;
                Head      = Head.Next;
            }
            Count++;
        }//end Push
Exemplo n.º 7
0
        }     //end nodebyindex

        //add Object to list
        public void Add(object new_data)
        {
            NodeClass new_node = new NodeClass(new_data);

            //if head null dont add just reassign head
            if (Head == null)
            {
                Head = new_node;
                Tail = new_node;
            }
            else
            {
                //if head is occupied goto end of list and add node
                Tail.Next = new_node;
                Tail      = new_node;
            } //end if
            Count++;
        }     //end Add method
Exemplo n.º 8
0
        }//end Push

        //POP()

        public object Pop()
        {
            NodeClass CurrentNode = Tail;
            NodeClass ReturnNode  = null;

            while (CurrentNode.Next != Head)
            {
                CurrentNode = CurrentNode.Next;
            }//end while

            ReturnNode = CurrentNode.Next;

            CurrentNode.Next = null;

            Head = CurrentNode;

            Count--;

            return(ReturnNode.Data);
        }//end Pop
Exemplo n.º 9
0
        }     //end Add method

        //return index of item in list
        public int IndexOf(object SearchData)
        {
            int Loops = 1;
            int Index = -1;

            NodeClass New_Node = Head;

            while (New_Node.Next != null)
            {
                if (New_Node.Data == SearchData)
                {
                    Index = Loops;
                }

                Loops++;
                New_Node = New_Node.Next;
            }//end while

            return(Index);
        }//end indexof method
Exemplo n.º 10
0
        }//end remove method

        //clear list
        public void Clear()
        {
            Head = null;
        }//end clear method