Ejemplo n.º 1
0
    def merge(left,right):

        merge = Linked_list()
        merge.add(0)
        
        
        current = merge.head
        
    

        left_head = left.head
        
        right_head = right.head
      

        while left_head or right_head:
            

            if left_head is None:
                current.next_Node = right_head
                
                right_head = right_head.next_Node
                

            elif right_head is None:
                current.next_Node = left_head
                left_head = left_head.next_Node
            else:
                

                left_data = left_head.data    
                right_data = right_head.data 

                if left_data < right_data :
                    current.next_Node = left_head
                    left_head = left_head.next_Node
                else:
                    current.next_Node = right_head
                    right_head = right_head.next_Node
                   
            current = current.next_Node
            
        head = merge.head.next_Node    
        merge.head = head
        return merge
Ejemplo n.º 2
0
print(f"time of monitor: {(lastTime-StartTime)}")

#--------------------// chack if the List is sorted or not  \\--------------------
print("\n--------// chack if the List is sorted or not \\\\-------")
# print(alist)
# print(Sort.verify_sort(alist))
StartTime = time.perf_counter_ns()
sorted_list = Sort.merge_sort(alist)
EndTime = time.perf_counter_ns()
print(f"sorted_list {sorted_list} \ntime of monitor: {(EndTime-StartTime)}ns ")
# print(Sort.verify_sort(sorted_list))

#------------------// sort lkinked list \\-------------------------------------
print("\n--------// sort lkinked list \\\\-------")
l = Linked_list()
l.add(20)
l.add(30)
l.add(10)
l.add(5)
l.add(25)
l.add(40)
print(l)
sorted_link_list = Linked_list_sortition.sort_linked_list(l)
print(sorted_link_list)

#------------------// bogo sort \\-------------------------------------
print("\n-----------//bogo sort \\\\ ----------------")
alist1 = load_numbers("Data_Structures/Files/numers.txt")
StartTime = time.perf_counter_ns()
sorted_bogo = Sort.bogo_sort(alist1)
EndTime = time.perf_counter_ns()