Count nodes in Circular linked list

Given a circular linked list, count number of nodes in it

def get_length(self):
temp =self.head
count = 0
if temp == None:
return count
while(temp):
count +=1
temp = temp.next
if temp==self.head:
return count

--

--

--

Looking for my next opportunity to make change in a BIG way

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Telemetry and Application Insights in Testing.

How to safely extend your legacy code? Part I

COVID-19 BLE Solutions Index

Comparing Groupby in SQL and Pandas

Cloud Computing : The beginning

Ok so I got an assigement in an online course that u have to share your work with Others.

Good Practices to Become a Great iOS Developer

How to Use Different Types of Ansible Variables

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Sairam Penjarla

Sairam Penjarla

Looking for my next opportunity to make change in a BIG way

More from Medium

Snake and Ladder with Graphs

Speed Up Your Python classes with slot

Python — Inheritance ( Part One )

Data Structures in Plain English — Understanding Linked Lists