| |

VerySource

 Forgot password?
 Register
Search
Author: myjinx

C ++ masters help, give an answer

[Copy link]

0

Threads

6

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 China

Post time: 2020-6-16 03:15:01
| Show all posts
#include "stdafx.h"

int main()
{
   int a[10] = {4,7,1,0,9,6,5,3,2,8};
   for(int i=0;i<10;++i)
   {
      int temp;
      if(a[0] <a[i])
      {
temp = a[0];
a[0] = a[i];
a[i] = temp;
      }
      if(a[9]> a[i])
      {
         temp = a[9];
a[9] = a[i];
a[i] = temp;
      }
   }
   for(int i=0;i<10;i++)
   cout<<a[i]<<endl;
}
Reply

Use magic Report

0

Threads

6

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 China

Post time: 2020-6-16 15:15:01
| Show all posts
I am also a novice, and the program I write is inevitably still very young
Make the master laugh
Reply

Use magic Report

0

Threads

5

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 China

Post time: 2020-6-16 20:30:01
| Show all posts
to :sun88888

This seems to destroy the order of other arrays that do not need to be exchanged!
Reply

Use magic Report

0

Threads

3

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-6-22 18:45:01
| Show all posts
Just take a moment, the complexity is at most 0 (N)
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list