@rajeevsinghthakur

reveres the array

September 21, 2021 · Python
def reversedArray(A,start,end):
    while start<end:
        A[start],A[end] = A[end],A[start]
        start += 1
        end -= 1
        
A = [1,2,3,4,5,6]

reversedArray(A,0,5)

print(A)

find max and min value in array

updated October 02, 2021 · Python
def max_check(x):
  max_val = x[0] 
  for check in x: 
    if check > max_val: 
      max_val = check 
  return max_val


def min_check(x):
  min_val = x[0] 
  for check in x: 

merging two sorted arrays

September 17, 2021 · Python
def mergearry(a1,a2,n1,n2):
    a3 = [None] * (n1+n2)
    i=j=k=0
    while i<n1 and j<n2:
        if a1[i]<a2[j]:
            a3[k] = a1[i]
            i += 1 
            k += 1 
        else:
            a3[k]=a2[j]
            j += 1 

Balance Brackets Problem

September 16, 2021 · Python
open_list = ["[","{","("]
close_list = ["]","}",")"]
def check(mysrt):
    stack =[]
    for i in mysrt:
        if i in open_list:
            stack.append(i)
        elif i in close_list:
            pos = close_list.index(i)
            if ((len(stack) > 0) and
                (open_list[pos] == stack[len(stack)-1])):

linked list and operations

updated September 16, 2021 · Python
class Node:
    def __init__(self,data):
        self.data = data
        self.next = None
class linkedlist:
    def __init__(self):
        self.head = None
    def push(self,data):
        data = Node(data)
        data.next=self.head
        self.head=data