コード例 #1
0
        public int Top()
        {
            int tmp = head.Value;

            head = head.Next;
            return(tmp);
        }
コード例 #2
0
        public override string ToString()
        {
            if (IsEmpty)
            {
                return("Список пуст");
            }
            NodeInt       currentNode = Head;
            StringBuilder listString  = new StringBuilder($"[{Head.ToString()}]");

            while (currentNode.Next != null)
            {
                currentNode = currentNode.Next;
                listString.AppendFormat($" [{currentNode.ToString()}]");
            }
            return(listString.ToString());
        }
コード例 #3
0
        public int InsertInOrder(int value)
        {
            int compareCount = 0;

            if (IsEmpty)
            {
                head = new NodeInt(value);
                return(1);
            }
            if (value <= head.Value)
            {
                head = new NodeInt(value, head);
                return(1);
            }
            NodeInt currentNode = head;

            while (currentNode.Next != null && value > currentNode.Next.Value)
            {
                currentNode = currentNode.Next;
                compareCount++;
            }
            currentNode.Next = new NodeInt(value, currentNode.Next);
            return(compareCount);
        }
コード例 #4
0
 public NodeInt(int value, NodeInt next)
 {
     Value = value;
     Next  = next;
 }
コード例 #5
0
 public NodeInt(int value)
 {
     Value = value;
     Next  = null;
 }
コード例 #6
0
 public IntList()
 {
     head = null;
 }