Example #1
0
        ////////////////////////////////////////////////////////////////////////////////////////////////////
        /// <summary>   Print link list. </summary>
        ///
        /// <remarks>   Galarist, 18/09/2018. </remarks>
        ///
        /// <param name="nodeList"> List of nodes. </param>
        ///
        /// <returns>   A string. </returns>
        ////////////////////////////////////////////////////////////////////////////////////////////////////

        public static string PrintLinkList(LinkListNodeList nodeList)
        {
            //goes through each node in the link list and builds a string to be displayed for all incorrect answers
            StringBuilder sb = new StringBuilder();

            sb.Append("HEAD");
            if (nodeList.HeadNode.GetNext() != null)
            {
                //add each incorrect node string to the string builder until the tail node is reached
                sb.Append("<-> " + nodeList.HeadNode.NodeToString());
                nodeList.CurrentNode = nodeList.HeadNode.GetNext();
                while (nodeList.CurrentNode != null)
                {
                    if (nodeList.CurrentNode.GetMyValue().IsCorrect == false)
                    {
                        sb.Append(" <-> " + nodeList.CurrentNode.NodeToString());
                        nodeList.CurrentNode = nodeList.CurrentNode.GetNext();
                    }
                    else
                    {
                        nodeList.CurrentNode = nodeList.CurrentNode.GetNext();
                    }
                }
            }
            sb.Append(" <-> TAIL");
            return(sb.ToString());
        }
Example #2
0
        //Hash table of all nodes

        ////////////////////////////////////////////////////////////////////////////////////////////////////
        /// <summary>   Node hast table. </summary>
        ///
        /// <remarks>   Galarist, 18/09/2018. </remarks>
        ///
        /// <param name="nodeList"> List of nodes. </param>
        ///
        /// <returns>   A Hashtable. </returns>
        ////////////////////////////////////////////////////////////////////////////////////////////////////

        public static Hashtable NodeHastTable(LinkListNodeList nodeList)
        {
            //returns a hash table containing all the nodes
            Hashtable tempTable = new Hashtable();
            int       count     = 1;

            //loop over the link list and add all the nodes to the hash table
            for (LinkListNode i = nodeList.CurrentNode; i.GetNext() != null; i = i.GetNext())
            {
                tempTable.Add(count.ToString(), i);
                count++;
            }
            return(tempTable);
        }