Sorting in linear time(hackers block)

i am not able to run my code properly. i guess there is some problem with my code. please check it.

https://ide.codingblocks.com/s/101790 - this is the url of the code

Hello @Ayushi21,

There are two syntax errors:

  1. cout<<arr[i]<""; // <<
  2. you have forget to close the braces “}” for if condition.

There are two logical errors:

  1. high=8;
  2. for (int i=0; i<9;i++)

In both the cases you are doing the same mistake.
What is the size of your array? and what are you taking the values of i and high?

Correct them and your code will run.

Suggestion:
If you have to submit this code then add the cin statement to take input.
And change the value of high and i accordingly.

Hope, this would help.
Give a like if you are satisfied.

hello. this is the url of the correct code-- https://ide.codingblocks.com/s/101790 please can you check this i am not getting the output and i have corrected every mistake i guess

Correct the following:

  1. How are you so sure that there are only 5 elements in the array i.e. there would be no test case with less or more number of elements.

  2. what is the meaning of this statement?
    cin>>arr[5];
    it means you are storing the input at arr[5].

  3. you are just reading the number of elements in the array and storing it at position arr[5].

  4. if you declare an array as int arr[5], then the only possible index that you can access is from 0 to 4 i.e. for arr[n] : 0 to n-1.
    But, in your code you are accessing arr[5], which is out of range.

  5. The way you are sending input is also wrong:
    5
    0,1,2,1,2
    don’t use “,”, rather use space.

Modification:

  1. first take input for n i.e number of elements in array.
    int n;
    cin>>n;

  2. declare an array of size n.
    int arr[n];

  3. input the elements of array.
    for(int i=0;i<n;i++){
    cin>>arr[i];
    }

Hope, this will resolve your doubts.
Give a like, if you are satisfied and mark this as resolved.

hello the code is compiling successfully but the output is not coming. https://ide.codingblocks.com/s/101790 - this is the url of the code with modifications.

And where is the rest of the code?
Now, you have erased the main logic of the code, i.e the sorting part.

oh sorry sent you by mistake. https://ide.codingblocks.com/s/102211 - this is the modified one

I have modified your code, check your mistakes.
Click here.

Give a like, if you are satisfied.

2 Likes

thank you for your help.

i won’t mind a like.:joy:

2 Likes