def Partition(l,x):
     if(l.search(x)):
         current=l.head
         #index=1
         while(current.getData()!=x):
             current=current.getNext()
             #index=index+1
         print("Current Element is",current.getData())
         #print("Current Element index is",index)
         temp=l.head
         previous=Node()
         previous.setNext(temp)
         tempIndex=1
         
         while(temp!=None):
             print("************")
             print("Previous is",previous.getData())
             print("Temp is",temp.getData())
             #print("current.getNext() is",current.getNext())
             print("************")
             exchange=False
             if(temp.getData()>current.getData()):
                 if(temp==l.head):
                     l.head=temp.getNext()
                 previous.setNext(temp.getNext())
                 temp.setNext(current.getNext())
                 current.setNext(temp)       
                 temp=previous
                 exchange=True
                 #l.show
                 
             if(temp.getData()<current.getData()):
                 previous.setNext(temp.getNext())
                 temp.setNext(l.head)
                 l.head=temp
                 temp=previous
                 exchange=True
             
             
             if(not exchange):
                 previous=previous.getNext()
             temp=previous.getNext()
             
             
             l.show()
     else:
        print("Item Not Present in LinkedList")
        return -1  
def  iSort(l): 
     current=l.head.getNext()
     previous=l.head
     previous.setNext(current)
     
     while(current!=None):
         exchange=False
         tempCurrent=l.head
         tempPrevious=Node()  
         tempPrevious.setNext(tempCurrent)
         #print("******************************")  
         #print("Current is",current.getData())
         #print("Previous is",previous.getData())
         
         while(tempCurrent!=current and (not exchange)):
             #print("tempCurrent is",tempCurrent.getData())
             #print("tempPrevious is",tempPrevious.getData())
             
             if (tempCurrent.getData()>current.getData()):
                 if(tempCurrent==l.head):
                     previous.setNext(current.getNext())
                     current.setNext(tempCurrent)
                     tempPrevious.setNext(current)
                     l.head=current
                     previous=current
                     current=current.getNext()
                     exchange=True
                     break
                 
                 previous.setNext(current.getNext())
                 current.setNext(tempCurrent)
                 tempPrevious.setNext(current)
                 current=previous.getNext()
                 exchange=True
                 break
             
             tempCurrent=tempCurrent.getNext()
             tempPrevious=tempPrevious.getNext()
         if(not exchange):
             current=current.getNext()
             previous=previous.getNext()
         
         #l.show()    
     return l