Man! I totally forgot the code this SORTING thing and now, I don't know how to do it again. I think having a vacation from programming was a bad idea... Any help contributions??? please...

Here's the problem :

-----------------------------------------------------------------------------------
A program that sorts the ten (10) input values either in ascending or descending order based on the user's choice.

* Use an array to store the input numbers.
* Use a function for sorting.
* Do not use global variables.
------------------------------------------------------------------------------------

#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>

using namespace std;



int main()
{
	vector<double> v;
	vector<double>::iterator p;

	for( int i = 0; i <= 10; ++i ) {
		cout << "Enter a number: ";
		double num;
		cin >> num;
		v.push_back(num);
	}
	cout << "Enter 1 for ascending or 2 for descending: ";
	int choice;
	cin >> choice;

	switch( choice )
	{
	case 1:
		sort( v.begin(), v.end() );
		for( p = v.begin(); p != v.end(); ++p )
			cout << *p << endl;
		cout << endl;
		break;

	case 2:
		sort( v.begin(), v.end(), greater<int>() );
		for( p = v.begin(); p != v.end(); ++p )
			cout << *p << endl;
		cout << endl;
		break;
	}

	return 0;
}

thanks man. it really helps a lot! and oh, by the way, here's another kind of sorting that I have figured out:(it's a beginner type, simple but it works.)

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#define N 10

void sort(int data[10])
{
	int e,j,temp;
	for(e=0;e<N;e++)
	{
		for(j=e+1;j<N;j++)
		{
			if(data[e]>data[j])
			{
				temp=data[e];
				data[e]=data[j];
				data[j]=temp;
			}
		}
	}
	printf("\n\n\tSorted as: ");
	for(e=0;e<N;e++)
	         printf("%d ",data[e]);
	getch();
	main();
}
main()
{
	int i[N],e;
	clrscr();
	printf("Enter 10 integers: \n\n");
	for(e=0;e<10;e++)
	{
		scanf("%d",&i[e]);
	}
	sort(i);
}

I kept it as simple as I could. hehehe. thanks man. You're one of the best! :)

getch();
	main();
}
main()
{
	int i[N],e;
	clrscr();

Yeeeeeeeeech!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.