首页 > 解决方案 > 如何从双向链表c#中打印每个列表中的素数(每行五个数字)

问题描述

如何从文本文件的双向链表中显示素数?

 public void middleOfList()
        {

            if (head == null) ;
            if (head.next == null || head.next.next == null) ;


            Node slow = head, fast = head.next.next;

            // iterate till the middle element
            while (fast != null && fast.next != null)
            {
                slow = slow.next;//Add New nodeto the middle of the linked list.
                fast = fast.next.next; //Add new node to the last of the linked list.
            }


            if (fast != null) slow = slow.next;

            Console.WriteLine("The Middle number of list is: " + slow.data);
        } 

    }

标签: c#doubly-linked-list

解决方案


推荐阅读