human
Count of Prime Nodes of a Singly Linked List | Function to check if a number is prime.
Corner cases.
This is checked so that we can skip middle five numbers in below loop.
Link list node.
Push a new node on the front of the list ..
Function to find count of prime nodes in a linked list.
If current node is prime.
Update count.
Driver Code.
Start with the empty list.
create the linked list 15 -> 5 -> 6 -> 10 -> 17.
Function call to print require answer"
Solution in Python:
assistant
#Here is code to count of Prime Nodes of a Singly Linked List and the other steps required.
 def isPrime ( n ) :
	if n <= 1 :
		return False
	if n <= 3 :
		return True
	if n % 2 == 0 or n % 3 == 0 :
		return False
	i = 5
	while i * i <= n :
		if n % i == 0 or n % ( i + 2 ) == 0 :
			return False
		i += 6
	return True
class Node :
	def __init__ ( self , data , next ) :
		self . data = data
		self . next = next
class LinkedList :
	def __init__ ( self ) :
		self . head = None
	def push ( self , new_data ) :
		new_node = Node ( new_data , self . head )
		self . head = new_node
	def countPrime ( self ) :
		count = 0
		ptr = self . head
		while ptr != None :
			if isPrime ( ptr . data ) :
				count += 1
			ptr = ptr . next
		return count
if __name__ == " _ _ main _ _ " :
	linkedlist = LinkedList ( )
	linkedlist . push ( 17 )
	linkedlist . push ( 10 )
	linkedlist . push ( 6 )
	linkedlist . push ( 5 )
	linkedlist . push ( 15 )
	print ( " Count ▁ of ▁ prime ▁ nodes ▁ = " , linkedlist . countPrime ( ) )