6 Replies - 452 Views - Last Post: 13 August 2019 - 04:32 AM Rate Topic: -----

#1 adgajax   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 11-August 19

What will be in line 1 and line 2

Posted 11 August 2019 - 01:55 PM

#include <iostream>
#include <algorithm>
using namespace std;
// define compare function to compare between char i and j
 _____________________{       // Line-1: Write proper function header

      _____________________;   // Line-2: Write correct function body
   
}
int main() {
    char data[5];

    for (int i = 0; i < 5; i++)
        cin >> data[i];

    sort(data, data + 5, compare);

    for (int i = 0; i < 5; i++)
        cout << data[i] << " ";

    return 0;
}



can anyone explain how does the sort and compare function's working, like there are no arguments passing in compare function then how and what it is going to return

Is This A Good Question/Topic? 0
  • +

Replies To: What will be in line 1 and line 2

#2 modi123_1   User is offline

  • Suitor #2
  • member icon



Reputation: 15270
  • View blog
  • Posts: 61,223
  • Joined: 12-June 08

Re: What will be in line 1 and line 2

Posted 11 August 2019 - 02:03 PM

What have you tried, thought about, or considered?
Was This Post Helpful? 0
  • +
  • -

#3 jimblumberg   User is offline

  • member icon

Reputation: 5762
  • View blog
  • Posts: 17,641
  • Joined: 25-December 09

Re: What will be in line 1 and line 2

Posted 11 August 2019 - 02:09 PM

Did you research the std::sort() function, in particular the comparison function?

Jim
Was This Post Helpful? 0
  • +
  • -

#4 adgajax   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 11-August 19

Re: What will be in line 1 and line 2

Posted 11 August 2019 - 02:19 PM

I searched for std::sort()but its taking only two arguments the array and array+length of array, but in the above program the function is also passed as argument there are three arguments
Was This Post Helpful? 0
  • +
  • -

#5 Skydiver   User is online

  • Code herder
  • member icon

Reputation: 7056
  • View blog
  • Posts: 24,003
  • Joined: 05-May 12

Re: What will be in line 1 and line 2

Posted 11 August 2019 - 04:35 PM

See (3) in the cppreference.com. It's std::sort() that takes 3 parameters.
Was This Post Helpful? 0
  • +
  • -

#6 adgajax   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 11-August 19

Re: What will be in line 1 and line 2

Posted 12 August 2019 - 10:35 PM

Can anyone tell me what will be the line 1 and line 2
Was This Post Helpful? 0
  • +
  • -

#7 Skydiver   User is online

  • Code herder
  • member icon

Reputation: 7056
  • View blog
  • Posts: 24,003
  • Joined: 05-May 12

Re: What will be in line 1 and line 2

Posted 13 August 2019 - 04:32 AM

Yes.
Line 1 will have the function name, parameters, and return type.
Line 2 will have your code to implement the function.

We will not do your homework for you. Beware that you are treading very close to gimme-the-codez territory and having this thread shutdown.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1