A program sorts an array of integer. Write down the code that tests the sorting algorithm of written in a program.

Facebook Google Plus YouTube

Combined Bank(HBFC and KB)

Assistant Programmer-2018

Description: given array of size number, write a program to check if it is sorted in Ascending order or not.

Description: given array of size number, write a program to check if it is sorted in Ascending order or not.

Input: 10, 11,12,13,14

Output: True

Input: 20, 21,22,23,24

Output: True

Input: 20, 11.19,13,12

Output: False

Source code

#include <bits/stdc++. h>

#include <iostream>

using namespace std;

int sortTest (int arraList[], int nunber)

{

    int i;

        if(nunber==1 || nunber==0)

        return true;

        for(i=0;i<nunber;i++)

        if(arraList[i-1]>arraList[i])

        return false;

    return true;

}

int main()

{

    int arraList[5] = {1,2,4,6,7};

    int number=5;

    if(sortTest(arraList,number))

    cout<<“True”;

    else

    cout<<“True”;

}

Leave a Reply

%d bloggers like this: