Skip to content

working with better function approach #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 15 additions & 25 deletions linkdedlist/middle_of_ll.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,33 +11,23 @@ def push(self , new_node):
new_node = node(new_node)
new_node.next = self.head
self.head = new_node
def binaryfunc(arr, l, r, x):
while l<=r:

#finding the mid values
mid = int(l+(r-l) / 2)

def middle_element(self):
temp = self.head
count = 0
while(temp):
count += 1
#print(temp.data)
temp = temp.next
#print(mid)
#print(type(mid))

#checking condition if mid value is equal to search value or not
if(arr[mid] == x):
return mid


middle = count/2 + 1
print(count)
print(middle)
print(type(middle))
#if not and value is greater than mid value ignore left part and increase its value
elif arr[mid] < x:
l = mid+1

count = 1
temp = self.head
print('here the value is')
print(count)
print(middle)
print('above initial values')
while(temp):
if (count == middle):
print(temp.data)
break
else:
temp = temp.next
count += 1
#print(temp.data)
print('error')
Expand All @@ -63,4 +53,4 @@ def middle_element(self):
llist.push(512)
llist.push(33)
llist.push(334)
llist.middle_element()
llist.middle_element()