sorting

I am trying to sort numbers entered from largest to smallest.
and i did just print the largest number entered , and the rest are left out
can anyone help me out .









#include <iostream>
#include <vector>
#include <string>
using namespace std ;
int main ()
{
vector <int> go ;
vector <int> you ;
int v ;
for (v; cin>>v;)
go.push_back(v) ;

for (int u =0 ; u<go.size() ; u++)
{
if (go[u] > go[v])
go[v] = go[u] ;
cout<<go[v]<<endl;



}




}
Last edited on
I suggest you try to comment your program that which command do which work.
And maybe you can make up your mind, cause your code is almost all wrong,..

and, look at your V, WT* you want it to be ? VALUE ? INDEX?

And also, format your code to be kind of something looks lovely to read it.
All of this has happened before...

http://www.cplusplus.com/forum/windows/20781/
that post has code examples of many different sorting methods.

you should use bubble sort.
you can make a function to do that.
for example,this program will ask the user for 5 numbers,then sorts them:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include <iostream.h>
#include <conio.h>
void input(int [], int);    //a function used to get 5 numbers from the user
void bubble(int [], int);     //a function used to sort the numbers
void goutput(int [], int);
int main()
{
  const int k=5;
  int numbers[5];
  clrscr();                          //clears the screen
  ginput(numbers, k);
  bubble(numbers, k);
  cout << "the sorted data are:\n";
  goutput(temp, k);
  getch();
  return 0;
}
//functions
void ginput(int number[], int len)
{
  int i;
  for (i=0;i<=len;i++) {
        cout << "Enter number " << (i+1) << ":";
        cin >> number[i];
     }
}

void bubble(int number[], int len)
{
    int i, j, item;
    for(i = len-1;i>0;i--)
         for(j=0;j<i;j++)
              if (number[j] > temp[i+1] {
                  item=temp[j];
                  number[j]=number[j+1];
                  number[j+1]=item;
          }
}

void goutput(int number[], int len)
{
  int i;
  for(i=0;i<len;i++)
      cout << temp[i] << " ";
}

this is the output:

Enter number 1: 25
Enter number 2: 57
Enter number 3: 48
Enter number 4: 37
Enter number 5: 12
the sorted date are:
12 25 37 48 57

hope this helps!
Topic archived. No new replies allowed.