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

HOW CAN YOU DO THIS? I SEEN OTHER ANSWERS BUT THEY ARE NOT CLEAR ENOUGH... CAN S

ID: 3752171 • Letter: H

Question

HOW CAN YOU DO THIS? I SEEN OTHER ANSWERS BUT THEY ARE NOT CLEAR ENOUGH... CAN SOMONE SCREEN SHOT THE PROGRAM OR COPY AND PASTE? WITH THE OUTPUT? I WANT THIS TO BE A SIMPLE PROGRAM WHERE I CAN INPUT THE LIST IN ONE LINE NOT DO SO MANY LISTINGS...

THANKS,

Class Node:

                         def __init__(self,initdata):

                               self.data = initdata

                               self.next = none

                   Class OrderedList:

                          def __init__(self):

                                self.head = None

For an ordered linked-list, write an algorithm called count which will count the number of occurrences of a specific piece of data. First, you have to create the linked list using the following input (note: this should be an ordered list - how will we do this?).

2, 5, 10, 14, 18, 23, 23, 23, 25, 26, 29, 31, 35, 37.

Next , think about how we will count the duplicates (pseudocode: 5 points, Python code: 15 points)? The functions you will need are given in the book and on CANVAS (code 3.21a). We have reviewed these in class.

Explanation / Answer


class Node:
def __init__(slf, info):
slf.info = info
slf.next = None
  
class LinkedList:
def __init__(slf):
slf.head = None
def count(slf, searchFor):
current = slf.head
count = 0
while(current is not None):
if current.info == searchFor:
count += 1
current = current.next
return count
def push(slf, new_data):
new_node = Node(new_data)
new_node.next = slf.head
slf.head = new_node
def printList(slf):
temporary = slf.head
while(temporary):
print temporary.info,
temporary = temporary.next
Listt = LinkedList()
Listt.push(1)
Listt.push(3)
Listt.push(1)
Listt.push(2)
Listt.push(1)
print "count of 1 is %d" %(Listt.count(1))