Friday, February 1, 2019

Merge sort

  • Problem Description

    Write a program to perform merge sorting
  • CODING ARENA
  • a=int(input())
    x=[]
    for i in range(a):
        b=int(input())
        x.append(b)
    for i in range(a):
        for j in range(a):
            if(x[i]<x[j]):
                temp=x[i]
                x[i]=x[j]
                x[j]=temp
    print(x)
  • Test Case 1

    Input (stdin)
    7
    
    8
    
    2
    
    4
    
    9
    
    3
    
    6
    
    1
    
    
    Expected Output
    [1, 2, 3, 4, 6, 8, 9]
  • Test Case 2

    Input (stdin)
    7
    
    7
    
    6
    
    5
    
    4
    
    3
    
    2
    
    1
    
    
    Expected Output
    [1, 2, 3, 4, 5, 6, 7]

No comments:

Post a Comment