• We just launched and are currently in beta. Join us as we build and grow the community.

Selection Sort in C++

dadafak

Patch Maker
D Rep
0
0
0
Rep
0
D Vouches
0
0
0
Vouches
0
Posts
80
Likes
14
Bits
2 MONTHS
2 2 MONTHS OF SERVICE
LEVEL 1 200 XP
Selection Sort in C++. By this method, you can easily sort a for loop code and array. Below are the sample codes:

  1. #include<iostream>
  2. #include<conio.h>
  3. using namespace std;
  4. int

    main(

    )
  5. {
  6. int

    arraylength,

    num[

    1000

    ]

    ,

    num1,

    d,

    num2=

    0

    ;
  7. cout<<

    "Enter the total no. of element: "

    ;
  8. cin>>

    arraylength;

  9. for

    (

    int

    i=

    0

    ;

    i<

    arraylength;

    i++

    )
  10. {

    cout<<

    "Enter No."

    <<

    i+

    1

    <<

    ": "

    ;
  11. cin>>

    num[

    i]

    ,

    num[

    d]

    ;

    }

  12. {

    cout<<

    " \n

    "

    <<

    endl;

    }
  13. for

    (

    int

    d=

    0

    ;

    d<

    arraylength;

    d++

    )

    {
  14. cout<<

    num[

    d]

    <<

    " "

    <<

    "\n

    "

    <<

    endl;


  15. cout<<

    "UNSORTED ARRAY : "

    ;
  16. for

    (

    int

    i =

    0

    ;

    i<

    arraylength;

    i++

    )

    {
  17. cout<<

    num[

    i]

    <<

    " "

    ;
  18. }


  19. cout<<

    endl<<

    "SORTED ARRAY : "

    ;

  20. for

    (

    int

    a=

    0

    ;

    a<

    arraylength-

    1

    ;

    a++

    )

    {
  21. for

    (

    int

    b=

    0

    ;

    b<

    arraylength-

    a-

    1

    ;

    b++

    )

    {
  22. if

    (

    num[

    b]

    <

    num[

    b+

    1

    ]

    )

    {
  23. num1=

    num[

    b]

    ;
  24. num[

    b]

    =

    num[

    b+

    1

    ]

    ;
  25. num[

    b+

    1

    ]

    =

    num1;
  26. }
  27. }
  28. }
  29. for

    (

    int

    r=

    0

    ;

    r<

    arraylength;

    r++

    )

    {
  30. cout<<

    num[

    r]

    <<

    " "

    ;
  31. }
  32. }
  33. getch

    (

    )

    ;
  34. return

    0

    ;
  35. }

Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. After downloading it, you will need a program like Winzip to decompress it.

Virus note: All files are scanned once-a-day by SourceCodester.com for viruses, but new viruses come out every day, so no prevention program can catch 100% of them.

FOR YOUR OWN SAFETY, PLEASE:

1. Re-scan downloaded files using your personal virus checker before using it.

2. NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code.


Download
You must upgrade your account or reply in the thread to view the hidden content.
 

452,496

335,994

336,002

Top