From 3e87bedff899f6d592d85a536d9d4e2b83f2445e Mon Sep 17 00:00:00 2001 From: bhumilsarvaiya Date: Mon, 5 Sep 2016 01:56:23 +0530 Subject: [PATCH] Update linkedlist.py --- linkedlist.py | 83 +++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 80 insertions(+), 3 deletions(-) diff --git a/linkedlist.py b/linkedlist.py index a8ef5b0..a9a98c5 100644 --- a/linkedlist.py +++ b/linkedlist.py @@ -1,6 +1,6 @@ ''' @Description: Simple Singly Linked List implementation in python -@Author: Albert Mundu +@Author: Albert Mundu, Bhumil Sarvaiya ''' class Node(object): @@ -28,11 +28,88 @@ def insert(self,data): def delete(self): self.head=self.head.next_node + def clean(self): + self.head=None + + def refined_delete(self): + if(self.head==None): + pass + elif(self.head.next_node==None): + self.head=None + else: + self.head=self.head.next_node + def display(self): tmp=self.head while tmp!=None: print tmp.data, tmp=tmp.next_node print "" - - + + def get_first_element(self): + tmp=self.head + return tmp.data + + def get_first_element_refined(self): + if(self.head==None): + return -1 + tmp=self.head + return tmp.data + + def get_last_element(self): + tmp=self.head + while tmp!=None: + data=tmp.data + tmp=tmp.next_node + return data + + def find_min(self,x): + minimum=10000 + tmpy=self.head + tmpx=x.head + while tmpy!=None: + if(tmpy.datamaximum): + maximum=tmpy.data + x=tmpx.data + tmpy=tmpy.next_node + tmpx=tmpx.next_node + return (maximum,x) + + def find_mid(self,x,window_size): + tmpx=x.head + tmpy=self.head + for i in range(int(window_size/2)): + y_value=tmpy.data + x_value=tmpx.data + tmpy=tmpy.next_node + tmpx=tmpx.next_node + return (y_value,x_value) + + def find_mid_refined(self,x,window_size): + tmpx=x.head + tmpy=self.head + first=tmpx.data + for i in range(int(window_size/2)): + y_value=tmpy.data + x_value=tmpx.data + if((x_value-first)>int(window_size/2)): + return (previous_y,previous_x) + previous_x=x_value + previous_y=y_value + if(tmpx.next_node==None): + return (previous_y,previous_x) + tmpy=tmpy.next_node + tmpx=tmpx.next_node + return (y_value,x_value)