def run(): singly_linked_list = BuildSinglyLinkedList(auto_populate=True).get_ll() k = 3 print('Given Linked List: ') singly_linked_list.print_linked_list() required_node = find_kth_node_from_end(singly_linked_list, k) print(f'\n{k}th node from end: ', required_node.data)
def run(): list_of_nodes = [12, 11, 13, 5, 6, 7, ] singly_linked_list = BuildSinglyLinkedList(list_of_nodes=list_of_nodes).get_ll() print('Linked List before sort: ') singly_linked_list.print_linked_list() new_head = get_merge_sorted_ll(singly_linked_list) sorted_ll = SinglyLinkedList(head=new_head) print('Linked List after sort: ') sorted_ll.print_linked_list()
def run(): singly_linked_list = BuildSinglyLinkedList(list_of_nodes=[ 60, ], auto_populate=True).get_ll() mid_node = find_mid_of_linked_list(singly_linked_list) print('Linked List: ', end='') singly_linked_list.print_linked_list() print('Mid is: ', end='') if mid_node: print(mid_node.data) else: print(mid_node)
def run(): singly_linked_list = BuildSinglyLinkedList(auto_populate=True).get_ll() print('Given Linked List: ') singly_linked_list.print_linked_list() print('\nLinked List after reversal: ') new_head = reverse_linked_list(singly_linked_list) singly_linked_list.head = new_head singly_linked_list.print_linked_list()
def run(): singly_ll_1 = BuildSinglyLinkedList(list_of_nodes=[10, 30, 50, 80, 90]).get_ll() singly_ll_2 = BuildSinglyLinkedList(list_of_nodes=[20, 40, 50, 70]).get_ll() print('Sorted Linked list-1: ') singly_ll_1.print_linked_list() print('Sorted Linked list-2: ') singly_ll_2.print_linked_list() new_sorted_mergd_ll = SinglyLinkedList(head=get_sorted_merged_ll(singly_ll_1, singly_ll_2)) print('New sorted Linked list after merge: ') new_sorted_mergd_ll.print_linked_list()
def run(): # num1 = BuildSinglyLinkedList(list_of_nodes=[6, 4, 9, 5, 7, ]).get_ll() # represents num = 64957 # num2 = BuildSinglyLinkedList(list_of_nodes=[4, 8, ]).get_ll() # represents num = 48 num1 = BuildSinglyLinkedList(list_of_nodes=[5, 6, 3, ]).get_ll() # represents num = 563 num2 = BuildSinglyLinkedList(list_of_nodes=[8, 4, 2, 1, ]).get_ll() # represents num = 842 print('Given numbers to be summed are: ') print('num1: ') num1.print_linked_list() print('num2: ') num2.print_linked_list() # summed_num = GetLLSum(num1=num1, num2=num2).get_numbers_sum() summed_num = GetLLSum(num1=num1, num2=num2).get_numbers_sum(use_recursion=True) print('Sum of given numbers is: ') summed_num.print_stack()
def run(): unsorted_singly_singly_list = BuildSinglyLinkedList( list_of_nodes=[10, 50, 30, 20, 10], auto_populate=True).get_ll() print('Given Lined List: ') unsorted_singly_singly_list.print_linked_list() print('\nLinked List after duplicate removal: ') remove_duplicates_from_unsorted_list(unsorted_singly_singly_list) unsorted_singly_singly_list.print_linked_list()
def run(): singly_linked_list = BuildSinglyLinkedList(list_of_nodes=[ 60, 70, 80, 90, 100, ], auto_populate=True).get_ll() k = 3 print('Given Linked List: ') singly_linked_list.print_linked_list() print('\nLinked List after reverse action: ') new_head = reverse_in_group_of_k(singly_linked_list, k) singly_linked_list.head = new_head singly_linked_list.print_linked_list()
def run(): list_of_nodes = [ 10, 10, 20, 30, 30, 30, ] sorted_singly_singly_list = BuildSinglyLinkedList( list_of_nodes=list_of_nodes).get_ll() print('Given Lined List: ') sorted_singly_singly_list.print_linked_list() print('\nLinked List after duplicate removal: ') remove_duplicates_from_sorted_list(sorted_singly_singly_list) sorted_singly_singly_list.print_linked_list()
def run(): list_of_nodes = [ 60, 70, 80, 90, 100, 110, 120, 130, ] singly_linked_list = BuildSinglyLinkedList(list_of_nodes=list_of_nodes, auto_populate=True).get_ll() m = 2 n = 2 print('Given Linked List:') singly_linked_list.print_linked_list() delete_n_nodes_after_every_m_nodes(singly_linked_list, m, n) print('\nLinked List after deletion: ') singly_linked_list.print_linked_list()
def run(): singly_linked_list = BuildSinglyLinkedList(auto_populate=True).get_ll() recursively_print_linked_list(singly_linked_list)