Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Working in python: This will be in Python We have used the node structure and a

ID: 670509 • Letter: W

Question

Working in python:

This will be in Python

We have used the node structure and a linked-list structure as shown below:

                   Class Node:

                         def __init__(self,initdata):

                               self.data = initdata

                               self.next = none

                   Class UnorderedList:

                          def __init__(self):

                                self.head = None

Now, for an unordered linked-list, I need to write an algorithm called count which will count the number of occurrences of a specific piece of data. The count I belive is in there, I am unsure how to check it. The code I am using is below, if anyone can add something to it in order to check it, as I cannot prove it is counting in its current state.

Note: Please use identation when copying/pasting the code, thank you!

Thank you

Code I have so far:

class Node:

    def __init__(self,initdata):

        self.data = initdata

        self.next = none

class UnorderedList:

    def __init__(self):

        self.head = None

    def size(self):

        current = self.head

        count = 0

        while current != None:

            count = count + 1

            current = current.getNext()

        return count

Explanation / Answer

class Node:
def __init__(self,initdata):
self.data = initdata
self.next = None

class UnorderedList:
def __init__(self):
self.head = None
def size(self):
current = self.head
count = 0
while current != None:
count = count + 1
current = current.next
return count

example = UnorderedList()
example.head = Node(5)
print example.size()

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote